mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04: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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{}{}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user