Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unnecessary assertion to any #1333

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions sample/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ func (s *RulesBasedSampler) Start() error {

func (s *RulesBasedSampler) SetClusterSize(size int) {
for _, sampler := range s.samplers {
// Sampler does not implement ClusterSizer.
// By asserting Sampler to an empty interface, we will have access to the underlying pointer.
// We can then assert that pointer to the ClusterSizer.
if sampler, ok := sampler.(any).(ClusterSizer); ok {
if sampler, ok := sampler.(ClusterSizer); ok {
sampler.SetClusterSize(size)
}
}
Expand Down
8 changes: 4 additions & 4 deletions sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (s *SamplerFactory) updatePeerCounts() {

// all the samplers who want it should use the stored count
for _, sampler := range s.samplers {
// Sampler does not implement ClusterSizer.
// By asserting Sampler to an empty interface, we will have access to the underlying pointer.
// We can then assert that pointer to the ClusterSizer.
if clusterSizer, ok := sampler.(any).(ClusterSizer); ok {
if clusterSizer, ok := sampler.(ClusterSizer); ok {
s.Logger.Warn().Logf("set cluster size to %d", s.peerCount)
clusterSizer.SetClusterSize(s.peerCount)
} else {
s.Logger.Warn().Logf("sampler does not implement ClusterSizer")
}
}
}
Expand Down
Loading