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:
parent
55a01dadaa
commit
dbd1c047cb
19 changed files with 14 additions and 165 deletions
|
@ -173,8 +173,7 @@ func setVersion() {
|
|||
// Only set the appVersion if -ldflags was used
|
||||
if gitNearestTag != "" || gitTag != "" {
|
||||
if devBuild && gitNearestTag != "" {
|
||||
appVersion = fmt.Sprintf("%s (+%s %s)",
|
||||
strings.TrimPrefix(gitNearestTag, "v"), GitCommit, buildDate)
|
||||
appVersion = fmt.Sprintf("%s (+%s %s)", strings.TrimPrefix(gitNearestTag, "v"), GitCommit, buildDate)
|
||||
} else if gitTag != "" {
|
||||
appVersion = strings.TrimPrefix(gitTag, "v")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -4,9 +4,10 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
|
||||
// Hook in CoreDNS.
|
||||
_ "github.com/coredns/coredns/core"
|
||||
// Load all managed plugins in github.com/coredns/coredns
|
||||
_ "github.com/coredns/coredns/core/plugin"
|
||||
|
||||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue