aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2019-06-25 08:00:33 +0100
committerGravatar Yong Tang <yong.tang.github@outlook.com> 2019-06-25 15:00:33 +0800
commitcd176f859b2e71d8919c56ff67235c226ab5b48e (patch)
treee1ee9a8c19d3e198627e289dd998caebfa53bb21
parent123628dc469ec90b2414931988ee27993d2d9648 (diff)
downloadcoredns-cd176f859b2e71d8919c56ff67235c226ab5b48e.tar.gz
coredns-cd176f859b2e71d8919c56ff67235c226ab5b48e.tar.zst
coredns-cd176f859b2e71d8919c56ff67235c226ab5b48e.zip
Run gofmt -s and golint on the codebase (#2918)
* Run gofmt -s and golint on the codebase Run golint and fix everythign it flagged (except the context arg ordering), mostly edits in the rewrite plugin. Signed-off-by: Miek Gieben <miek@miek.nl> * ... and ofcourse the test as well Signed-off-by: Miek Gieben <miek@miek.nl>
-rw-r--r--plugin/chaos/zowners.go2
-rw-r--r--plugin/kubernetes/controller_test.go10
-rw-r--r--plugin/log/setup.go2
-rw-r--r--plugin/rewrite/reverter.go23
-rw-r--r--plugin/rewrite/rewrite.go4
-rw-r--r--plugin/rewrite/ttl.go76
-rw-r--r--plugin/rewrite/ttl_test.go22
-rw-r--r--plugin/tls/tls_test.go2
8 files changed, 72 insertions, 69 deletions
diff --git a/plugin/chaos/zowners.go b/plugin/chaos/zowners.go
index 7d5f296ca..d747069dc 100644
--- a/plugin/chaos/zowners.go
+++ b/plugin/chaos/zowners.go
@@ -1,4 +1,4 @@
package chaos
// Owners are all GitHub handlers of all maintainers.
-var Owners = []string{"bradbeam", "chrisohaver", "dilyevsky", "ekleiner", "fastest963", "greenpau", "grobie", "inigohu", "isolus", "johnbelamaric", "miekg", "nchrisdk", "nitisht", "pmoroney", "rajansandeep", "rdrozhdzh", "rtreffer", "stp-ip", "superq", "varyoo", "yongtang"} \ No newline at end of file
+var Owners = []string{"bradbeam", "chrisohaver", "dilyevsky", "ekleiner", "fastest963", "greenpau", "grobie", "inigohu", "isolus", "johnbelamaric", "miekg", "nchrisdk", "nitisht", "pmoroney", "rajansandeep", "rdrozhdzh", "rtreffer", "stp-ip", "superq", "varyoo", "yongtang"}
diff --git a/plugin/kubernetes/controller_test.go b/plugin/kubernetes/controller_test.go
index 7e1f9dd29..37d4705e4 100644
--- a/plugin/kubernetes/controller_test.go
+++ b/plugin/kubernetes/controller_test.go
@@ -79,7 +79,7 @@ func generateEndpoints(cidr string, client kubernetes.Interface) {
}
ep.ObjectMeta.Name = "svc" + strconv.Itoa(count)
_, err = client.CoreV1().Endpoints("testns").Create(ep)
- count += 1
+ count++
}
}
@@ -94,17 +94,17 @@ func generateSvcs(cidr string, svcType string, client kubernetes.Interface) {
case "clusterip":
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
createClusterIPSvc(count, client, ip)
- count += 1
+ count++
}
case "headless":
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
createHeadlessSvc(count, client, ip)
- count += 1
+ count++
}
case "external":
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
createExternalSvc(count, client, ip)
- count += 1
+ count++
}
default:
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
@@ -115,7 +115,7 @@ func generateSvcs(cidr string, svcType string, client kubernetes.Interface) {
} else if count%3 == 2 {
createExternalSvc(count, client, ip)
}
- count += 1
+ count++
}
}
}
diff --git a/plugin/log/setup.go b/plugin/log/setup.go
index b9ecb1f72..be3256704 100644
--- a/plugin/log/setup.go
+++ b/plugin/log/setup.go
@@ -104,7 +104,7 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
classes[response.All] = struct{}{}
}
- for i := len(rules) - 1; i >= length; i -= 1 {
+ for i := len(rules) - 1; i >= length; i-- {
rules[i].Class = classes
}
}
diff --git a/plugin/rewrite/reverter.go b/plugin/rewrite/reverter.go
index 570b7d39e..5a55c7ad5 100644
--- a/plugin/rewrite/reverter.go
+++ b/plugin/rewrite/reverter.go
@@ -1,10 +1,11 @@
package rewrite
import (
- "github.com/miekg/dns"
"regexp"
"strconv"
"strings"
+
+ "github.com/miekg/dns"
)
// ResponseRule contains a rule to rewrite a response with.
@@ -13,7 +14,7 @@ type ResponseRule struct {
Type string
Pattern *regexp.Regexp
Replacement string
- Ttl uint32
+ TTL uint32
}
// ResponseReverter reverses the operations done on the question section of a packet.
@@ -39,10 +40,12 @@ func (r *ResponseReverter) WriteMsg(res *dns.Msg) error {
res.Question[0] = r.originalQuestion
if r.ResponseRewrite {
for _, rr := range res.Answer {
- var isNameRewritten bool = false
- var isTtlRewritten bool = false
- var name string = rr.Header().Name
- var ttl uint32 = rr.Header().Ttl
+ var (
+ isNameRewritten bool
+ isTTLRewritten bool
+ name = rr.Header().Name
+ ttl = rr.Header().Ttl
+ )
for _, rule := range r.ResponseRules {
if rule.Type == "" {
rule.Type = "name"
@@ -63,14 +66,14 @@ func (r *ResponseReverter) WriteMsg(res *dns.Msg) error {
name = s
isNameRewritten = true
case "ttl":
- ttl = rule.Ttl
- isTtlRewritten = true
+ ttl = rule.TTL
+ isTTLRewritten = true
}
}
- if isNameRewritten == true {
+ if isNameRewritten {
rr.Header().Name = name
}
- if isTtlRewritten == true {
+ if isTTLRewritten {
rr.Header().Ttl = ttl
}
}
diff --git a/plugin/rewrite/rewrite.go b/plugin/rewrite/rewrite.go
index 64283df92..906523326 100644
--- a/plugin/rewrite/rewrite.go
+++ b/plugin/rewrite/rewrite.go
@@ -51,7 +51,7 @@ func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
return dns.RcodeServerFailure, fmt.Errorf("invalid name after rewrite: %s", x)
}
respRule := rule.GetResponseRule()
- if respRule.Active == true {
+ if respRule.Active {
wr.ResponseRewrite = true
wr.ResponseRules = append(wr.ResponseRules, respRule)
}
@@ -128,7 +128,7 @@ func newRule(args ...string) (Rule, error) {
case "edns0":
return newEdns0Rule(mode, args[startArg:]...)
case "ttl":
- return newTtlRule(mode, args[startArg:]...)
+ return newTTLRule(mode, args[startArg:]...)
default:
return nil, fmt.Errorf("invalid rule type %q", args[0])
}
diff --git a/plugin/rewrite/ttl.go b/plugin/rewrite/ttl.go
index b29762213..73445dfc9 100644
--- a/plugin/rewrite/ttl.go
+++ b/plugin/rewrite/ttl.go
@@ -12,31 +12,31 @@ import (
//"github.com/miekg/dns"
)
-type exactTtlRule struct {
+type exactTTLRule struct {
NextAction string
From string
ResponseRule
}
-type prefixTtlRule struct {
+type prefixTTLRule struct {
NextAction string
Prefix string
ResponseRule
}
-type suffixTtlRule struct {
+type suffixTTLRule struct {
NextAction string
Suffix string
ResponseRule
}
-type substringTtlRule struct {
+type substringTTLRule struct {
NextAction string
Substring string
ResponseRule
}
-type regexTtlRule struct {
+type regexTTLRule struct {
NextAction string
Pattern *regexp.Regexp
ResponseRule
@@ -44,7 +44,7 @@ type regexTtlRule struct {
// Rewrite rewrites the current request based upon exact match of the name
// in the question section of the request.
-func (rule *exactTtlRule) Rewrite(ctx context.Context, state request.Request) Result {
+func (rule *exactTTLRule) Rewrite(ctx context.Context, state request.Request) Result {
if rule.From == state.Name() {
return RewriteDone
}
@@ -52,7 +52,7 @@ func (rule *exactTtlRule) Rewrite(ctx context.Context, state request.Request) Re
}
// Rewrite rewrites the current request when the name begins with the matching string.
-func (rule *prefixTtlRule) Rewrite(ctx context.Context, state request.Request) Result {
+func (rule *prefixTTLRule) Rewrite(ctx context.Context, state request.Request) Result {
if strings.HasPrefix(state.Name(), rule.Prefix) {
return RewriteDone
}
@@ -60,7 +60,7 @@ func (rule *prefixTtlRule) Rewrite(ctx context.Context, state request.Request) R
}
// Rewrite rewrites the current request when the name ends with the matching string.
-func (rule *suffixTtlRule) Rewrite(ctx context.Context, state request.Request) Result {
+func (rule *suffixTTLRule) Rewrite(ctx context.Context, state request.Request) Result {
if strings.HasSuffix(state.Name(), rule.Suffix) {
return RewriteDone
}
@@ -69,7 +69,7 @@ func (rule *suffixTtlRule) Rewrite(ctx context.Context, state request.Request) R
// Rewrite rewrites the current request based upon partial match of the
// name in the question section of the request.
-func (rule *substringTtlRule) Rewrite(ctx context.Context, state request.Request) Result {
+func (rule *substringTTLRule) Rewrite(ctx context.Context, state request.Request) Result {
if strings.Contains(state.Name(), rule.Substring) {
return RewriteDone
}
@@ -78,7 +78,7 @@ func (rule *substringTtlRule) Rewrite(ctx context.Context, state request.Request
// Rewrite rewrites the current request when the name in the question
// section of the request matches a regular expression.
-func (rule *regexTtlRule) Rewrite(ctx context.Context, state request.Request) Result {
+func (rule *regexTTLRule) Rewrite(ctx context.Context, state request.Request) Result {
regexGroups := rule.Pattern.FindStringSubmatch(state.Name())
if len(regexGroups) == 0 {
return RewriteIgnored
@@ -86,8 +86,8 @@ func (rule *regexTtlRule) Rewrite(ctx context.Context, state request.Request) Re
return RewriteDone
}
-// newTtlRule creates a name matching rule based on exact, partial, or regex match
-func newTtlRule(nextAction string, args ...string) (Rule, error) {
+// newTTLRule creates a name matching rule based on exact, partial, or regex match
+func newTTLRule(nextAction string, args ...string) (Rule, error) {
if len(args) < 2 {
return nil, fmt.Errorf("too few (%d) arguments for a ttl rule", len(args))
}
@@ -98,50 +98,50 @@ func newTtlRule(nextAction string, args ...string) (Rule, error) {
if len(args) == 3 {
s = args[2]
}
- ttl, valid := isValidTtl(s)
- if valid == false {
+ ttl, valid := isValidTTL(s)
+ if !valid {
return nil, fmt.Errorf("invalid TTL '%s' for a ttl rule", s)
}
if len(args) == 3 {
switch strings.ToLower(args[0]) {
case ExactMatch:
- return &exactTtlRule{
+ return &exactTTLRule{
nextAction,
plugin.Name(args[1]).Normalize(),
ResponseRule{
Active: true,
Type: "ttl",
- Ttl: ttl,
+ TTL: ttl,
},
}, nil
case PrefixMatch:
- return &prefixTtlRule{
+ return &prefixTTLRule{
nextAction,
plugin.Name(args[1]).Normalize(),
ResponseRule{
Active: true,
Type: "ttl",
- Ttl: ttl,
+ TTL: ttl,
},
}, nil
case SuffixMatch:
- return &suffixTtlRule{
+ return &suffixTTLRule{
nextAction,
plugin.Name(args[1]).Normalize(),
ResponseRule{
Active: true,
Type: "ttl",
- Ttl: ttl,
+ TTL: ttl,
},
}, nil
case SubstringMatch:
- return &substringTtlRule{
+ return &substringTTLRule{
nextAction,
plugin.Name(args[1]).Normalize(),
ResponseRule{
Active: true,
Type: "ttl",
- Ttl: ttl,
+ TTL: ttl,
},
}, nil
case RegexMatch:
@@ -149,13 +149,13 @@ func newTtlRule(nextAction string, args ...string) (Rule, error) {
if err != nil {
return nil, fmt.Errorf("invalid regex pattern in a ttl rule: %s", args[1])
}
- return &regexTtlRule{
+ return &regexTTLRule{
nextAction,
regexPattern,
ResponseRule{
Active: true,
Type: "ttl",
- Ttl: ttl,
+ TTL: ttl,
},
}, nil
default:
@@ -165,51 +165,51 @@ func newTtlRule(nextAction string, args ...string) (Rule, error) {
if len(args) > 3 {
return nil, fmt.Errorf("many few arguments for a ttl rule")
}
- return &exactTtlRule{
+ return &exactTTLRule{
nextAction,
plugin.Name(args[0]).Normalize(),
ResponseRule{
Active: true,
Type: "ttl",
- Ttl: ttl,
+ TTL: ttl,
},
}, nil
}
// Mode returns the processing nextAction
-func (rule *exactTtlRule) Mode() string { return rule.NextAction }
-func (rule *prefixTtlRule) Mode() string { return rule.NextAction }
-func (rule *suffixTtlRule) Mode() string { return rule.NextAction }
-func (rule *substringTtlRule) Mode() string { return rule.NextAction }
-func (rule *regexTtlRule) Mode() string { return rule.NextAction }
+func (rule *exactTTLRule) Mode() string { return rule.NextAction }
+func (rule *prefixTTLRule) Mode() string { return rule.NextAction }
+func (rule *suffixTTLRule) Mode() string { return rule.NextAction }
+func (rule *substringTTLRule) Mode() string { return rule.NextAction }
+func (rule *regexTTLRule) Mode() string { return rule.NextAction }
// GetResponseRule return a rule to rewrite the response with. Currently not implemented.
-func (rule *exactTtlRule) GetResponseRule() ResponseRule {
+func (rule *exactTTLRule) GetResponseRule() ResponseRule {
return rule.ResponseRule
}
// GetResponseRule return a rule to rewrite the response with. Currently not implemented.
-func (rule *prefixTtlRule) GetResponseRule() ResponseRule {
+func (rule *prefixTTLRule) GetResponseRule() ResponseRule {
return rule.ResponseRule
}
// GetResponseRule return a rule to rewrite the response with. Currently not implemented.
-func (rule *suffixTtlRule) GetResponseRule() ResponseRule {
+func (rule *suffixTTLRule) GetResponseRule() ResponseRule {
return rule.ResponseRule
}
// GetResponseRule return a rule to rewrite the response with. Currently not implemented.
-func (rule *substringTtlRule) GetResponseRule() ResponseRule {
+func (rule *substringTTLRule) GetResponseRule() ResponseRule {
return rule.ResponseRule
}
// GetResponseRule return a rule to rewrite the response with.
-func (rule *regexTtlRule) GetResponseRule() ResponseRule {
+func (rule *regexTTLRule) GetResponseRule() ResponseRule {
return rule.ResponseRule
}
-// validTtl returns true if v is valid TTL value.
-func isValidTtl(v string) (uint32, bool) {
+// validTTL returns true if v is valid TTL value.
+func isValidTTL(v string) (uint32, bool) {
i, err := strconv.Atoi(v)
if err != nil {
return uint32(0), false
diff --git a/plugin/rewrite/ttl_test.go b/plugin/rewrite/ttl_test.go
index 5ede4cdae..359807299 100644
--- a/plugin/rewrite/ttl_test.go
+++ b/plugin/rewrite/ttl_test.go
@@ -12,7 +12,7 @@ import (
"github.com/miekg/dns"
)
-func TestNewTtlRule(t *testing.T) {
+func TestNewTTLRule(t *testing.T) {
tests := []struct {
next string
args []string
@@ -36,7 +36,7 @@ func TestNewTtlRule(t *testing.T) {
}
for i, tc := range tests {
failed := false
- rule, err := newTtlRule(tc.next, tc.args...)
+ rule, err := newTTLRule(tc.next, tc.args...)
if err != nil {
failed = true
}
@@ -71,13 +71,13 @@ func TestTtlRewrite(t *testing.T) {
args []string
expectedType reflect.Type
}{
- {[]string{"stop", "ttl", "srv1.coredns.rocks", "1"}, reflect.TypeOf(&exactTtlRule{})},
- {[]string{"stop", "ttl", "exact", "srv15.coredns.rocks", "15"}, reflect.TypeOf(&exactTtlRule{})},
- {[]string{"stop", "ttl", "prefix", "srv30", "30"}, reflect.TypeOf(&prefixTtlRule{})},
- {[]string{"stop", "ttl", "suffix", "45.coredns.rocks", "45"}, reflect.TypeOf(&suffixTtlRule{})},
- {[]string{"stop", "ttl", "substring", "rv50", "50"}, reflect.TypeOf(&substringTtlRule{})},
- {[]string{"stop", "ttl", "regex", `(srv10)\.(coredns)\.(rocks)`, "10"}, reflect.TypeOf(&regexTtlRule{})},
- {[]string{"stop", "ttl", "regex", `(srv20)\.(coredns)\.(rocks)`, "20"}, reflect.TypeOf(&regexTtlRule{})},
+ {[]string{"stop", "ttl", "srv1.coredns.rocks", "1"}, reflect.TypeOf(&exactTTLRule{})},
+ {[]string{"stop", "ttl", "exact", "srv15.coredns.rocks", "15"}, reflect.TypeOf(&exactTTLRule{})},
+ {[]string{"stop", "ttl", "prefix", "srv30", "30"}, reflect.TypeOf(&prefixTTLRule{})},
+ {[]string{"stop", "ttl", "suffix", "45.coredns.rocks", "45"}, reflect.TypeOf(&suffixTTLRule{})},
+ {[]string{"stop", "ttl", "substring", "rv50", "50"}, reflect.TypeOf(&substringTTLRule{})},
+ {[]string{"stop", "ttl", "regex", `(srv10)\.(coredns)\.(rocks)`, "10"}, reflect.TypeOf(&regexTTLRule{})},
+ {[]string{"stop", "ttl", "regex", `(srv20)\.(coredns)\.(rocks)`, "20"}, reflect.TypeOf(&regexTTLRule{})},
}
for i, r := range ruleset {
rule, err := newRule(r.args...)
@@ -90,10 +90,10 @@ func TestTtlRewrite(t *testing.T) {
}
rules = append(rules, rule)
}
- doTtlTests(rules, t)
+ doTTLTests(rules, t)
}
-func doTtlTests(rules []Rule, t *testing.T) {
+func doTTLTests(rules []Rule, t *testing.T) {
tests := []struct {
from string
fromType uint16
diff --git a/plugin/tls/tls_test.go b/plugin/tls/tls_test.go
index aeef9e6bc..2def130a5 100644
--- a/plugin/tls/tls_test.go
+++ b/plugin/tls/tls_test.go
@@ -50,7 +50,7 @@ func TestTLS(t *testing.T) {
func TestTLSClientAuthentication(t *testing.T) {
// Invalid configurations are tested in the general test case. In this test we only look into specific details of valid client_auth options.
tests := []struct {
- option string // tls plugin option(s)
+ option string // tls plugin option(s)
expectedType tls.ClientAuthType // expected authentication type.
}{
// By default, or if 'nocert' is specified, no cert should be requested.