Skip to content

Commit

Permalink
general: use map[string]struct{} instead of map[string]bool
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentbernat committed Aug 5, 2022
1 parent 15fd354 commit c014899
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions conntrackfixer/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ func (c *Component) Start() error {
if !strings.HasSuffix(string(rport), "/udp") {
continue
}
ports := map[string]bool{}
ports := map[string]struct{}{}
for _, binding := range bindings {
ports[binding.HostPort] = true
ports[binding.HostPort] = struct{}{}
}
for hportStr := range ports {
hport, err := strconv.ParseUint(hportStr, 10, 16)
Expand Down
4 changes: 2 additions & 2 deletions console/sankey.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ func (c *Component) sankeyHandlerFunc(gc *gin.Context) {
completeName := func(name string, index int) string {
return fmt.Sprintf("%s: %s", input.Dimensions[index].String(), name)
}
addedNodes := map[string]bool{}
addedNodes := map[string]struct{}{}
addNode := func(name string) {
if _, ok := addedNodes[name]; !ok {
addedNodes[name] = true
addedNodes[name] = struct{}{}
output.Nodes = append(output.Nodes, name)
}
}
Expand Down
6 changes: 3 additions & 3 deletions inlet/geoip/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ func (c *Component) Start() error {
c.r.Err(err).Msg("cannot setup watcher for GeoIP databases")
return fmt.Errorf("cannot setup watcher: %w", err)
}
dirs := map[string]bool{}
dirs := map[string]struct{}{}
if c.config.GeoDatabase != "" {
dirs[filepath.Dir(c.config.GeoDatabase)] = true
dirs[filepath.Dir(c.config.GeoDatabase)] = struct{}{}
}
if c.config.ASNDatabase != "" {
dirs[filepath.Dir(c.config.ASNDatabase)] = true
dirs[filepath.Dir(c.config.ASNDatabase)] = struct{}{}
}
for k := range dirs {
if err := watcher.Add(k); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions inlet/snmp/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type realPoller struct {
config pollerConfig
clock clock.Clock

pendingRequests map[string]bool
pendingRequests map[string]struct{}
pendingRequestsLock sync.Mutex
errLogger reporter.Logger
put func(exporterIP, exporterName string, ifIndex uint, iface Interface)
Expand All @@ -51,7 +51,7 @@ func newPoller(r *reporter.Reporter, config pollerConfig, clock clock.Clock, put
r: r,
config: config,
clock: clock,
pendingRequests: make(map[string]bool),
pendingRequests: make(map[string]struct{}),
errLogger: r.Sample(reporter.BurstSampler(10*time.Second, 3)),
put: put,
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (p *realPoller) Poll(ctx context.Context, exporter string, port uint16, com
key := fmt.Sprintf("%s@%d", exporter, ifIndex)
_, ok := p.pendingRequests[key]
if !ok {
p.pendingRequests[key] = true
p.pendingRequests[key] = struct{}{}
filteredIfIndexes = append(filteredIfIndexes, ifIndex)
keys = append(keys, key)
}
Expand Down
1 change: 0 additions & 1 deletion orchestrator/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Component struct {

serviceLock sync.Mutex
serviceConfigurations map[ServiceType][]interface{}
registeredServices map[ServiceType][]map[string]bool
}

// Dependencies define the dependencies of the broker.
Expand Down

0 comments on commit c014899

Please sign in to comment.