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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 14 additions and 165 deletions

View file

@ -173,8 +173,7 @@ func setVersion() {
// Only set the appVersion if -ldflags was used // Only set the appVersion if -ldflags was used
if gitNearestTag != "" || gitTag != "" { if gitNearestTag != "" || gitTag != "" {
if devBuild && gitNearestTag != "" { if devBuild && gitNearestTag != "" {
appVersion = fmt.Sprintf("%s (+%s %s)", appVersion = fmt.Sprintf("%s (+%s %s)", strings.TrimPrefix(gitNearestTag, "v"), GitCommit, buildDate)
strings.TrimPrefix(gitNearestTag, "v"), GitCommit, buildDate)
} else if gitTag != "" { } else if gitTag != "" {
appVersion = strings.TrimPrefix(gitTag, "v") appVersion = strings.TrimPrefix(gitTag, "v")
} }

View file

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

View file

@ -20,7 +20,7 @@ func (a Auto) Walk() error {
toDelete[n] = true 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() { if info == nil || info.IsDir() {
return nil return nil
} }

View file

@ -16,13 +16,13 @@ import (
func init() { plugin.Register("cancel", setup) } func init() { plugin.Register("cancel", setup) }
func setup(c *caddy.Controller) error { func setup(c *caddy.Controller) error {
ca := Cancel{timeout: 5001 * time.Millisecond} ca := Cancel{}
for c.Next() { for c.Next() {
args := c.RemainingArgs() args := c.RemainingArgs()
switch len(args) { switch len(args) {
case 0: case 0:
break ca.timeout = 5001 * time.Millisecond
case 1: case 1:
dur, err := time.ParseDuration(args[0]) dur, err := time.ParseDuration(args[0])
if err != nil { 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 { func testMsgDname() *dns.Msg {
return &dns.Msg{ return &dns.Msg{
Answer: []dns.RR{ Answer: []dns.RR{

View file

@ -30,13 +30,9 @@ type (
TapMessage(message *tap.Message) TapMessage(message *tap.Message)
Pack() bool 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 type ContextKey string
const ( const (

View file

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

View file

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

View file

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

View file

@ -195,7 +195,7 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
}, },
}, nil }, nil
default: 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 { 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) return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, wr, r)
} }
case RewriteIgnored: case RewriteIgnored:
break
} }
} }
if rw.noRevert || len(wr.ResponseRules) == 0 { if rw.noRevert || len(wr.ResponseRules) == 0 {

View file

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

View file

@ -159,7 +159,7 @@ func newTTLRule(nextAction string, args ...string) (Rule, error) {
}, },
}, nil }, nil
default: 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 { 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 { for _, template := range h.Templates {
data, match, fthrough := template.match(ctx, state, zone) data, match, fthrough := template.match(ctx, state)
if !match { if !match {
if !fthrough { if !fthrough {
return dns.RcodeNameError, nil return dns.RcodeNameError, nil
@ -143,11 +143,11 @@ func executeRRTemplate(server, section string, template *gotmpl.Template, data *
return rr, nil 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] q := state.Req.Question[0]
data := &templateData{md: metadata.ValueFuncs(ctx)} data := &templateData{md: metadata.ValueFuncs(ctx)}
zone = plugin.Zones(t.zones).Matches(state.Name()) zone := plugin.Zones(t.zones).Matches(state.Name())
if zone == "" { if zone == "" {
return data, false, true return data, false, true
} }

View file

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

View file

@ -1,2 +1,2 @@
// Package test contains function and types useful for writing tests // Package test contains function and types useful for writing tests.
package test package test

View file

@ -1,72 +0,0 @@
package test
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
)
// Go get external example plugin, compile it into CoreDNS
// and check if it is really there, but running coredns -plugins.
// Dangerous test as it messes with your git tree, maybe use tag?
func testExternalPluginCompile(t *testing.T) {
if err := addExamplePlugin(); err != nil {
t.Fatal(err)
}
defer run(t, gitReset)
if _, err := run(t, goGet); err != nil {
t.Fatal(err)
}
if _, err := run(t, goGen); err != nil {
t.Fatal(err)
}
if _, err := run(t, goBuild); err != nil {
t.Fatal(err)
}
out, err := run(t, coredns)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(out), "dns.example") {
t.Fatal("Plugin dns.example should be there")
}
}
func run(t *testing.T, c *exec.Cmd) ([]byte, error) {
c.Dir = ".."
out, err := c.Output()
if err != nil {
return nil, fmt.Errorf("run: failed to run %s %s: %q", c.Args[0], c.Args[1], err)
}
return out, nil
}
func addExamplePlugin() error {
f, err := os.OpenFile("../plugin.cfg", os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(example)
return err
}
var (
goBuild = exec.Command("go", "build")
goGen = exec.Command("go", "generate")
goGet = exec.Command("go", "get", "github.com/coredns/example")
gitReset = exec.Command("git", "checkout", "core/*")
coredns = exec.Command("./coredns", "-plugins")
)
const example = "1001:example:github.com/coredns/example"

View file

@ -1,43 +0,0 @@
package test
import (
"testing"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
// Load all managed plugins in github.com/coredns/coredns
_ "github.com/coredns/coredns/core/plugin"
)
func benchmarkLookupBalanceRewriteCache(b *testing.B) {
t := new(testing.T)
name, rm, err := test.TempFile(".", exampleOrg)
if err != nil {
t.Fatalf("Failed to create zone: %s", err)
}
defer rm()
corefile := `example.org:0 {
file ` + name + `
rewrite type ANY HINFO
loadbalance
}
`
ex, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
defer ex.Stop()
c := new(dns.Client)
m := new(dns.Msg)
m.SetQuestion("example.org.", dns.TypeA)
b.ResetTimer()
for i := 0; i < b.N; i++ {
c.Exchange(m, udp)
}
}

View file

@ -4,9 +4,10 @@ import (
"sync" "sync"
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
// Hook in CoreDNS. // Hook in CoreDNS.
_ "github.com/coredns/coredns/core" _ "github.com/coredns/coredns/core"
// Load all managed plugins in github.com/coredns/coredns
_ "github.com/coredns/coredns/core/plugin"
"github.com/caddyserver/caddy" "github.com/caddyserver/caddy"
) )