Run gostaticheck (#3325)

* Run gostaticheck

Run gostaticcheck on the codebase and fix almost all flagged items.

Only keep

* coremain/run.go:192:2: var appVersion is unused (U1000)
* plugin/chaos/setup.go:54:3: the surrounding loop is unconditionally terminated (SA4004)
* plugin/etcd/setup.go:103:3: the surrounding loop is unconditionally terminated (SA4004)
* plugin/pkg/replacer/replacer.go:274:13: argument should be pointer-like to avoid allocations (SA6002)
* plugin/route53/setup.go:124:28: session.New is deprecated: Use NewSession functions to create sessions instead. NewSession has the same functionality as New except an error can be returned when the func is called instead of waiting to receive an error until a request is made.  (SA1019)
* test/grpc_test.go:25:69: grpc.WithTimeout is deprecated: use DialContext and context.WithTimeout instead.  Will be supported throughout 1.x.  (SA1019)

The first one isn't true, as this is set via ldflags. The rest is
minor. The deprecation should be fixed at some point; I'll file some
issues.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Make sure to plug in the plugins

import the plugins, that file that did this was removed, put it in the
reload test as this requires an almost complete coredns server.

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2019-10-01 07:41:29 +01:00
committed by GitHub
parent 55a01dadaa
commit dbd1c047cb
19 changed files with 14 additions and 165 deletions

View File

@@ -6,15 +6,12 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request"
"github.com/infobloxopen/go-trees/iptree"
"github.com/miekg/dns"
)
var log = clog.NewWithPlugin("acl")
// ACL enforces access control policies on DNS queries.
type ACL struct {
Next plugin.Handler

View File

@@ -20,7 +20,7 @@ func (a Auto) Walk() error {
toDelete[n] = true
}
filepath.Walk(a.loader.directory, func(path string, info os.FileInfo, err error) error {
filepath.Walk(a.loader.directory, func(path string, info os.FileInfo, _ error) error {
if info == nil || info.IsDir() {
return nil
}

View File

@@ -16,13 +16,13 @@ import (
func init() { plugin.Register("cancel", setup) }
func setup(c *caddy.Controller) error {
ca := Cancel{timeout: 5001 * time.Millisecond}
ca := Cancel{}
for c.Next() {
args := c.RemainingArgs()
switch len(args) {
case 0:
break
ca.timeout = 5001 * time.Millisecond
case 1:
dur, err := time.ParseDuration(args[0])
if err != nil {

View File

@@ -153,20 +153,6 @@ func testMsgCname() *dns.Msg {
}
}
func testDelegationMsg() *dns.Msg {
return &dns.Msg{
Ns: []dns.RR{
test.NS("miek.nl. 3600 IN NS linode.atoom.net."),
test.NS("miek.nl. 3600 IN NS ns-ext.nlnetlabs.nl."),
test.NS("miek.nl. 3600 IN NS omval.tednet.nl."),
},
Extra: []dns.RR{
test.A("omval.tednet.nl. 3600 IN A 185.49.141.42"),
test.AAAA("omval.tednet.nl. 3600 IN AAAA 2a04:b900:0:100::42"),
},
}
}
func testMsgDname() *dns.Msg {
return &dns.Msg{
Answer: []dns.RR{

View File

@@ -30,13 +30,9 @@ type (
TapMessage(message *tap.Message)
Pack() bool
}
tapContext struct {
context.Context
Dnstap
}
)
// ContextKey defines the type of key that is used to save data into the context
// ContextKey defines the type of key that is used to save data into the context.
type ContextKey string
const (

View File

@@ -6,14 +6,11 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/dnstap/dnstapio"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse"
"github.com/caddyserver/caddy"
)
var log = clog.NewWithPlugin("dnstap")
func init() { plugin.Register("dnstap", wrapSetup) }
func wrapSetup(c *caddy.Controller) error {

View File

@@ -5,7 +5,6 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
mwtls "github.com/coredns/coredns/plugin/pkg/tls"
"github.com/coredns/coredns/plugin/pkg/upstream"
@@ -13,8 +12,6 @@ import (
etcdcv3 "go.etcd.io/etcd/clientv3"
)
var log = clog.NewWithPlugin("etcd")
func init() { plugin.Register("etcd", setup) }
func setup(c *caddy.Controller) error {

View File

@@ -12,11 +12,8 @@ import (
// Proxy defines an upstream host.
type Proxy struct {
fails uint32
addr string
addr string
// Connection caching
expire time.Duration
transport *Transport
// health checking

View File

@@ -195,7 +195,7 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
},
}, nil
default:
return nil, fmt.Errorf("A name rule supports only exact, prefix, suffix, substring, and regex name matching, received: %s", matchType)
return nil, fmt.Errorf("name rule supports only exact, prefix, suffix, substring, and regex name matching, received: %s", matchType)
}
}
if len(args) == 7 {

View File

@@ -61,7 +61,6 @@ func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, wr, r)
}
case RewriteIgnored:
break
}
}
if rw.noRevert || len(wr.ResponseRules) == 0 {

View File

@@ -3,13 +3,10 @@ package rewrite
import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/caddyserver/caddy"
)
var log = clog.NewWithPlugin("rewrite")
func init() { plugin.Register("rewrite", setup) }
func setup(c *caddy.Controller) error {

View File

@@ -159,7 +159,7 @@ func newTTLRule(nextAction string, args ...string) (Rule, error) {
},
}, nil
default:
return nil, fmt.Errorf("A ttl rule supports only exact, prefix, suffix, substring, and regex name matching")
return nil, fmt.Errorf("ttl rule supports only exact, prefix, suffix, substring, and regex name matching")
}
}
if len(args) > 3 {

View File

@@ -73,7 +73,7 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
}
for _, template := range h.Templates {
data, match, fthrough := template.match(ctx, state, zone)
data, match, fthrough := template.match(ctx, state)
if !match {
if !fthrough {
return dns.RcodeNameError, nil
@@ -143,11 +143,11 @@ func executeRRTemplate(server, section string, template *gotmpl.Template, data *
return rr, nil
}
func (t template) match(ctx context.Context, state request.Request, zone string) (*templateData, bool, bool) {
func (t template) match(ctx context.Context, state request.Request) (*templateData, bool, bool) {
q := state.Req.Question[0]
data := &templateData{md: metadata.ValueFuncs(ctx)}
zone = plugin.Zones(t.zones).Matches(state.Name())
zone := plugin.Zones(t.zones).Matches(state.Name())
if zone == "" {
return data, false, true
}

View File

@@ -14,8 +14,6 @@ import (
"github.com/opentracing/opentracing-go/mocktracer"
)
const server = "coolServer"
func TestStartup(t *testing.T) {
m, err := traceParse(caddy.NewTestController("dns", `trace`))
if err != nil {