mirror of
https://github.com/coredns/coredns.git
synced 2025-12-06 02:15:11 -05:00
map bool -> map struct{} (#2386)
This clear out the remaining map[x]bool usage and moves the bool to an empty struct. Two note worthy other changes: * EnableChaos in the server is now also exported to make it show up in the documentation. * The auto plugin is left as is, because there the boolean is explicitaly set to false to signal 'to-be-deleted' and the key is left as-is. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -26,7 +26,7 @@ type Metrics struct {
|
||||
srv *http.Server
|
||||
|
||||
zoneNames []string
|
||||
zoneMap map[string]bool
|
||||
zoneMap map[string]struct{}
|
||||
zoneMu sync.RWMutex
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func New(addr string) *Metrics {
|
||||
met := &Metrics{
|
||||
Addr: addr,
|
||||
Reg: prometheus.NewRegistry(),
|
||||
zoneMap: make(map[string]bool),
|
||||
zoneMap: make(map[string]struct{}),
|
||||
}
|
||||
// Add the default collectors
|
||||
met.MustRegister(prometheus.NewGoCollector())
|
||||
@@ -69,7 +69,7 @@ func (m *Metrics) MustRegister(c prometheus.Collector) {
|
||||
// AddZone adds zone z to m.
|
||||
func (m *Metrics) AddZone(z string) {
|
||||
m.zoneMu.Lock()
|
||||
m.zoneMap[z] = true
|
||||
m.zoneMap[z] = struct{}{}
|
||||
m.zoneNames = keys(m.zoneMap)
|
||||
m.zoneMu.Unlock()
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (m *Metrics) OnFinalShutdown() error {
|
||||
return m.stopServer()
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
func keys(m map[string]struct{}) []string {
|
||||
sx := []string{}
|
||||
for k := range m {
|
||||
sx = append(sx, k)
|
||||
|
||||
@@ -50,25 +50,25 @@ func WithServer(ctx context.Context) string {
|
||||
return srv.(string)
|
||||
}
|
||||
|
||||
var monitorType = map[uint16]bool{
|
||||
dns.TypeAAAA: true,
|
||||
dns.TypeA: true,
|
||||
dns.TypeCNAME: true,
|
||||
dns.TypeDNSKEY: true,
|
||||
dns.TypeDS: true,
|
||||
dns.TypeMX: true,
|
||||
dns.TypeNSEC3: true,
|
||||
dns.TypeNSEC: true,
|
||||
dns.TypeNS: true,
|
||||
dns.TypePTR: true,
|
||||
dns.TypeRRSIG: true,
|
||||
dns.TypeSOA: true,
|
||||
dns.TypeSRV: true,
|
||||
dns.TypeTXT: true,
|
||||
var monitorType = map[uint16]struct{}{
|
||||
dns.TypeAAAA: struct{}{},
|
||||
dns.TypeA: struct{}{},
|
||||
dns.TypeCNAME: struct{}{},
|
||||
dns.TypeDNSKEY: struct{}{},
|
||||
dns.TypeDS: struct{}{},
|
||||
dns.TypeMX: struct{}{},
|
||||
dns.TypeNSEC3: struct{}{},
|
||||
dns.TypeNSEC: struct{}{},
|
||||
dns.TypeNS: struct{}{},
|
||||
dns.TypePTR: struct{}{},
|
||||
dns.TypeRRSIG: struct{}{},
|
||||
dns.TypeSOA: struct{}{},
|
||||
dns.TypeSRV: struct{}{},
|
||||
dns.TypeTXT: struct{}{},
|
||||
// Meta Qtypes
|
||||
dns.TypeIXFR: true,
|
||||
dns.TypeAXFR: true,
|
||||
dns.TypeANY: true,
|
||||
dns.TypeIXFR: struct{}{},
|
||||
dns.TypeAXFR: struct{}{},
|
||||
dns.TypeANY: struct{}{},
|
||||
}
|
||||
|
||||
const other = "other"
|
||||
|
||||
Reference in New Issue
Block a user