aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-12-10 10:17:15 +0000
committerGravatar Yong Tang <yong.tang.github@outlook.com> 2018-12-10 02:17:15 -0800
commit9abbf4a4a07a38af806791882566149418398d39 (patch)
treef8583a2ba923eab367759e0f75ddc813e43c9dd0 /plugin
parentc788649a0034246fbb325d5f0b66e8eb4d91ed54 (diff)
downloadcoredns-9abbf4a4a07a38af806791882566149418398d39.tar.gz
coredns-9abbf4a4a07a38af806791882566149418398d39.tar.zst
coredns-9abbf4a4a07a38af806791882566149418398d39.zip
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>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/kubernetes/xfr_test.go4
-rw-r--r--plugin/log/log.go6
-rw-r--r--plugin/log/log_test.go6
-rw-r--r--plugin/log/setup.go10
-rw-r--r--plugin/log/setup_test.go26
-rw-r--r--plugin/metrics/metrics.go8
-rw-r--r--plugin/metrics/vars/report.go36
7 files changed, 49 insertions, 47 deletions
diff --git a/plugin/kubernetes/xfr_test.go b/plugin/kubernetes/xfr_test.go
index dc6404c0c..db55aa8ed 100644
--- a/plugin/kubernetes/xfr_test.go
+++ b/plugin/kubernetes/xfr_test.go
@@ -129,9 +129,9 @@ func TestKubernetesXFRNotAllowed(t *testing.T) {
// difference shows what we're missing when comparing two RR slices
func difference(testRRs []dns.RR, gotRRs []dns.RR) []dns.RR {
- expectedRRs := map[string]bool{}
+ expectedRRs := map[string]struct{}{}
for _, rr := range testRRs {
- expectedRRs[rr.String()] = true
+ expectedRRs[rr.String()] = struct{}{}
}
foundRRs := []dns.RR{}
diff --git a/plugin/log/log.go b/plugin/log/log.go
index d963a134f..327bbf032 100644
--- a/plugin/log/log.go
+++ b/plugin/log/log.go
@@ -55,7 +55,9 @@ func (l Logger) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
class := response.Classify(tpe)
// If we don't set up a class in config, the default "all" will be added
// and we shouldn't have an empty rule.Class.
- if rule.Class[response.All] || rule.Class[class] {
+ _, ok := rule.Class[response.All]
+ _, ok1 := rule.Class[class]
+ if ok || ok1 {
rep := replacer.New(ctx, r, rrw, CommonLogEmptyValue)
clog.Infof(rep.Replace(rule.Format))
}
@@ -72,7 +74,7 @@ func (l Logger) Name() string { return "log" }
// Rule configures the logging plugin.
type Rule struct {
NameScope string
- Class map[response.Class]bool
+ Class map[response.Class]struct{}
Format string
}
diff --git a/plugin/log/log_test.go b/plugin/log/log_test.go
index 6d74f23ad..2de633aa5 100644
--- a/plugin/log/log_test.go
+++ b/plugin/log/log_test.go
@@ -21,7 +21,7 @@ func TestLoggedStatus(t *testing.T) {
rule := Rule{
NameScope: ".",
Format: DefaultLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}
var f bytes.Buffer
@@ -53,7 +53,7 @@ func TestLoggedClassDenial(t *testing.T) {
rule := Rule{
NameScope: ".",
Format: DefaultLogFormat,
- Class: map[response.Class]bool{response.Denial: true},
+ Class: map[response.Class]struct{}{response.Denial: struct{}{}},
}
var f bytes.Buffer
@@ -82,7 +82,7 @@ func TestLoggedClassError(t *testing.T) {
rule := Rule{
NameScope: ".",
Format: DefaultLogFormat,
- Class: map[response.Class]bool{response.Error: true},
+ Class: map[response.Class]struct{}{response.Error: struct{}{}},
}
var f bytes.Buffer
diff --git a/plugin/log/setup.go b/plugin/log/setup.go
index c3c1af4ca..4a2afceda 100644
--- a/plugin/log/setup.go
+++ b/plugin/log/setup.go
@@ -40,13 +40,13 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
rules = append(rules, Rule{
NameScope: ".",
Format: DefaultLogFormat,
- Class: make(map[response.Class]bool),
+ Class: make(map[response.Class]struct{}),
})
} else if len(args) == 1 {
rules = append(rules, Rule{
NameScope: dns.Fqdn(args[0]),
Format: DefaultLogFormat,
- Class: make(map[response.Class]bool),
+ Class: make(map[response.Class]struct{}),
})
} else {
// Name scope, and maybe a format specified
@@ -64,7 +64,7 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
rules = append(rules, Rule{
NameScope: dns.Fqdn(args[0]),
Format: format,
- Class: make(map[response.Class]bool),
+ Class: make(map[response.Class]struct{}),
})
}
@@ -82,14 +82,14 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
if err != nil {
return nil, err
}
- rules[len(rules)-1].Class[cls] = true
+ rules[len(rules)-1].Class[cls] = struct{}{}
}
default:
return nil, c.ArgErr()
}
}
if len(rules[len(rules)-1].Class) == 0 {
- rules[len(rules)-1].Class[response.All] = true
+ rules[len(rules)-1].Class[response.All] = struct{}{}
}
}
diff --git a/plugin/log/setup_test.go b/plugin/log/setup_test.go
index bf2ac3c3d..3c65c1c85 100644
--- a/plugin/log/setup_test.go
+++ b/plugin/log/setup_test.go
@@ -18,42 +18,42 @@ func TestLogParse(t *testing.T) {
{`log`, false, []Rule{{
NameScope: ".",
Format: DefaultLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}}},
{`log example.org`, false, []Rule{{
NameScope: "example.org.",
Format: DefaultLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}}},
{`log example.org. {common}`, false, []Rule{{
NameScope: "example.org.",
Format: CommonLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}}},
{`log example.org {combined}`, false, []Rule{{
NameScope: "example.org.",
Format: CombinedLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}}},
{`log example.org.
log example.net {combined}`, false, []Rule{{
NameScope: "example.org.",
Format: DefaultLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}, {
NameScope: "example.net.",
Format: CombinedLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}}},
{`log example.org {host}
log example.org {when}`, false, []Rule{{
NameScope: "example.org.",
Format: "{host}",
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}, {
NameScope: "example.org.",
Format: "{when}",
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}}},
{`log example.org {
@@ -61,28 +61,28 @@ func TestLogParse(t *testing.T) {
}`, false, []Rule{{
NameScope: "example.org.",
Format: CommonLogFormat,
- Class: map[response.Class]bool{response.All: true},
+ Class: map[response.Class]struct{}{response.All: struct{}{}},
}}},
{`log example.org {
class denial
}`, false, []Rule{{
NameScope: "example.org.",
Format: CommonLogFormat,
- Class: map[response.Class]bool{response.Denial: true},
+ Class: map[response.Class]struct{}{response.Denial: struct{}{}},
}}},
{`log {
class denial
}`, false, []Rule{{
NameScope: ".",
Format: CommonLogFormat,
- Class: map[response.Class]bool{response.Denial: true},
+ Class: map[response.Class]struct{}{response.Denial: struct{}{}},
}}},
{`log {
class denial error
}`, false, []Rule{{
NameScope: ".",
Format: CommonLogFormat,
- Class: map[response.Class]bool{response.Denial: true, response.Error: true},
+ Class: map[response.Class]struct{}{response.Denial: struct{}{}, response.Error: struct{}{}},
}}},
{`log {
class denial
@@ -90,7 +90,7 @@ func TestLogParse(t *testing.T) {
}`, false, []Rule{{
NameScope: ".",
Format: CommonLogFormat,
- Class: map[response.Class]bool{response.Denial: true, response.Error: true},
+ Class: map[response.Class]struct{}{response.Denial: struct{}{}, response.Error: struct{}{}},
}}},
{`log {
class abracadabra
diff --git a/plugin/metrics/metrics.go b/plugin/metrics/metrics.go
index 159eec014..2a87dcb17 100644
--- a/plugin/metrics/metrics.go
+++ b/plugin/metrics/metrics.go
@@ -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)
diff --git a/plugin/metrics/vars/report.go b/plugin/metrics/vars/report.go
index d0c64b864..f354b6551 100644
--- a/plugin/metrics/vars/report.go
+++ b/plugin/metrics/vars/report.go
@@ -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"