aboutsummaryrefslogtreecommitdiff
path: root/middleware
diff options
context:
space:
mode:
Diffstat (limited to 'middleware')
-rw-r--r--middleware/cache/setup.go2
-rw-r--r--middleware/dnssec/responsewriter.go12
-rw-r--r--middleware/file/reload_test.go2
-rw-r--r--middleware/file/secondary.go1
-rw-r--r--middleware/file/tree/less.go1
-rw-r--r--middleware/kubernetes/setup.go4
-rw-r--r--middleware/kubernetes/subzone_test.go2
-rw-r--r--middleware/metrics/metrics.go2
-rw-r--r--middleware/metrics/setup.go4
-rw-r--r--middleware/normalize.go10
-rw-r--r--middleware/pkg/rcode/rcode.go2
-rw-r--r--middleware/pkg/response/classify.go16
-rw-r--r--middleware/pkg/storage/fs.go2
-rw-r--r--middleware/pkg/storage/fs_test.go2
-rw-r--r--middleware/pprof/pprof.go7
-rw-r--r--middleware/secondary/setup.go2
-rw-r--r--middleware/test/helpers.go4
17 files changed, 42 insertions, 33 deletions
diff --git a/middleware/cache/setup.go b/middleware/cache/setup.go
index 05811a276..c0b09024b 100644
--- a/middleware/cache/setup.go
+++ b/middleware/cache/setup.go
@@ -56,7 +56,7 @@ func cacheParse(c *caddy.Controller) (int, []string, error) {
}
}
- for i, _ := range origins {
+ for i := range origins {
origins[i] = middleware.Host(origins[i]).Normalize()
}
return ttl, origins, nil
diff --git a/middleware/dnssec/responsewriter.go b/middleware/dnssec/responsewriter.go
index 0032fa7ba..95378c091 100644
--- a/middleware/dnssec/responsewriter.go
+++ b/middleware/dnssec/responsewriter.go
@@ -10,16 +10,16 @@ import (
"github.com/miekg/dns"
)
-type DnssecResponseWriter struct {
+type ResponseWriter struct {
dns.ResponseWriter
d Dnssec
}
-func NewDnssecResponseWriter(w dns.ResponseWriter, d Dnssec) *DnssecResponseWriter {
- return &DnssecResponseWriter{w, d}
+func NewDnssecResponseWriter(w dns.ResponseWriter, d Dnssec) *ResponseWriter {
+ return &ResponseWriter{w, d}
}
-func (d *DnssecResponseWriter) WriteMsg(res *dns.Msg) error {
+func (d *ResponseWriter) WriteMsg(res *dns.Msg) error {
// By definition we should sign anything that comes back, we should still figure out for
// which zone it should be.
state := request.Request{W: d.ResponseWriter, Req: res}
@@ -38,13 +38,13 @@ func (d *DnssecResponseWriter) WriteMsg(res *dns.Msg) error {
return d.ResponseWriter.WriteMsg(res)
}
-func (d *DnssecResponseWriter) Write(buf []byte) (int, error) {
+func (d *ResponseWriter) Write(buf []byte) (int, error) {
log.Printf("[WARNING] Dnssec called with Write: not signing reply")
n, err := d.ResponseWriter.Write(buf)
return n, err
}
-func (d *DnssecResponseWriter) Hijack() {
+func (d *ResponseWriter) Hijack() {
d.ResponseWriter.Hijack()
return
}
diff --git a/middleware/file/reload_test.go b/middleware/file/reload_test.go
index 1ba9f4bcf..02d789c66 100644
--- a/middleware/file/reload_test.go
+++ b/middleware/file/reload_test.go
@@ -39,7 +39,7 @@ func TestZoneReload(t *testing.T) {
t.Fatalf("expected 5 RRs, got %d", len(z.All()))
}
if err := ioutil.WriteFile(fileName, []byte(reloadZone2Test), 0644); err != nil {
- t.Fatalf("failed to write new zone data", err)
+ t.Fatalf("failed to write new zone data: %s", err)
}
// Could still be racy, but we need to wait a bit for the event to be seen
time.Sleep(1 * time.Second)
diff --git a/middleware/file/secondary.go b/middleware/file/secondary.go
index 9493a7fdd..ef44e124f 100644
--- a/middleware/file/secondary.go
+++ b/middleware/file/secondary.go
@@ -176,7 +176,6 @@ Restart:
}
}
}
- return nil
}
// The maximum difference between two serial numbers. If the difference between
diff --git a/middleware/file/tree/less.go b/middleware/file/tree/less.go
index 32d87b683..595dc9213 100644
--- a/middleware/file/tree/less.go
+++ b/middleware/file/tree/less.go
@@ -39,7 +39,6 @@ func less(a, b string) int {
i++
aj, bj = ai, bi
}
- return 0
}
func doDDD(b []byte) {
diff --git a/middleware/kubernetes/setup.go b/middleware/kubernetes/setup.go
index f976ba75b..dfa8c7ce4 100644
--- a/middleware/kubernetes/setup.go
+++ b/middleware/kubernetes/setup.go
@@ -107,7 +107,7 @@ func kubernetesParse(c *caddy.Controller) (Kubernetes, error) {
if len(args) != 0 {
k8s.ResyncPeriod, err = time.ParseDuration(args[0])
if err != nil {
- err = errors.New(fmt.Sprintf("Unable to parse resync duration value. Value provided was '%v'. Example valid values: '15s', '5m', '1h'. Error was: %v", args[0], err))
+ err = fmt.Errorf("Unable to parse resync duration value. Value provided was '%v'. Example valid values: '15s', '5m', '1h'. Error was: %v", args[0], err)
return Kubernetes{}, err
}
} else {
@@ -119,7 +119,7 @@ func kubernetesParse(c *caddy.Controller) (Kubernetes, error) {
labelSelectorString := strings.Join(args, " ")
k8s.LabelSelector, err = unversionedapi.ParseToLabelSelector(labelSelectorString)
if err != nil {
- err = errors.New(fmt.Sprintf("Unable to parse label selector. Value provided was '%v'. Error was: %v", labelSelectorString, err))
+ err = fmt.Errorf("Unable to parse label selector. Value provided was '%v'. Error was: %v", labelSelectorString, err)
return Kubernetes{}, err
}
} else {
diff --git a/middleware/kubernetes/subzone_test.go b/middleware/kubernetes/subzone_test.go
index c48e66c12..b1a9541b3 100644
--- a/middleware/kubernetes/subzone_test.go
+++ b/middleware/kubernetes/subzone_test.go
@@ -21,7 +21,7 @@ var examplesSubzoneConflict = map[string]bool{
"": false,
}
-func TestsubzoneConflict(t *testing.T) {
+func TestSubzoneConflict(t *testing.T) {
for z, expected := range examplesSubzoneConflict {
actual, conflicts := subzoneConflict(confZones, z)
diff --git a/middleware/metrics/metrics.go b/middleware/metrics/metrics.go
index 3a72bc3bb..a9d09c202 100644
--- a/middleware/metrics/metrics.go
+++ b/middleware/metrics/metrics.go
@@ -30,7 +30,7 @@ type Metrics struct {
Addr string
ln net.Listener
mux *http.ServeMux
- Once sync.Once
+ Once *sync.Once
ZoneNames []string
}
diff --git a/middleware/metrics/setup.go b/middleware/metrics/setup.go
index eee886f00..077a809d5 100644
--- a/middleware/metrics/setup.go
+++ b/middleware/metrics/setup.go
@@ -47,7 +47,7 @@ func prometheusParse(c *caddy.Controller) (Metrics, error) {
}
met.ZoneNames = make([]string, len(c.ServerBlockKeys))
copy(met.ZoneNames, c.ServerBlockKeys)
- for i, _ := range met.ZoneNames {
+ for i := range met.ZoneNames {
met.ZoneNames[i] = middleware.Host(met.ZoneNames[i]).Normalize()
}
args := c.RemainingArgs()
@@ -79,6 +79,6 @@ func prometheusParse(c *caddy.Controller) (Metrics, error) {
return met, err
}
-var metricsOnce sync.Once
+var metricsOnce *sync.Once
const addr = "localhost:9153"
diff --git a/middleware/normalize.go b/middleware/normalize.go
index e28ed96ea..2d153ba78 100644
--- a/middleware/normalize.go
+++ b/middleware/normalize.go
@@ -7,6 +7,7 @@ import (
"github.com/miekg/dns"
)
+// Zones respresents a lists of zone names.
type Zones []string
// Matches checks is qname is a subdomain of any of the zones in z. The match
@@ -27,7 +28,7 @@ func (z Zones) Matches(qname string) string {
// Normalize fully qualifies all zones in z.
func (z Zones) Normalize() {
- for i, _ := range z {
+ for i := range z {
z[i] = Name(z[i]).Normalize()
}
}
@@ -47,10 +48,11 @@ func (n Name) Matches(child string) bool {
// Normalize lowercases and makes n fully qualified.
func (n Name) Normalize() string { return strings.ToLower(dns.Fqdn(string(n))) }
-// Host represents a host from the Corefile, may contain port.
type (
- Host string
- Addr string
+ // Host represents a host from the Corefile, may contain port.
+ Host string // Host represents a host from the Corefile, may contain port.
+ // Addr resprents an address in the Corefile.
+ Addr string // Addr resprents an address in the Corefile.
)
// Normalize will return the host portion of host, stripping
diff --git a/middleware/pkg/rcode/rcode.go b/middleware/pkg/rcode/rcode.go
index 006440071..e871a96ca 100644
--- a/middleware/pkg/rcode/rcode.go
+++ b/middleware/pkg/rcode/rcode.go
@@ -6,6 +6,8 @@ import (
"github.com/miekg/dns"
)
+// ToString convert the rcode to the offical DNS string, or to "RCODE"+value if the RCODE
+// value is unknown.
func ToString(rcode int) string {
if str, ok := dns.RcodeToString[rcode]; ok {
return str
diff --git a/middleware/pkg/response/classify.go b/middleware/pkg/response/classify.go
index adbaa6526..65055dff4 100644
--- a/middleware/pkg/response/classify.go
+++ b/middleware/pkg/response/classify.go
@@ -2,14 +2,20 @@ package response
import "github.com/miekg/dns"
+// Type is the type of the message
type Type int
const (
- Success Type = iota
- NameError // NXDOMAIN in header, SOA in auth.
- NoData // NOERROR in header, SOA in auth.
- Delegation // NOERROR in header, NS in auth, optionally fluff in additional (not checked).
- OtherError // Don't cache these.
+ // Success indicates a positive reply
+ Success Type = iota
+ // NameError is a NXDOMAIN in header, SOA in auth.
+ NameError
+ // NoData indicated name found, but not the type: NOERROR in header, SOA in auth.
+ NoData
+ // Delegation is a msg with a pointer to another nameserver: NOERROR in header, NS in auth, optionally fluff in additional (not checked).
+ Delegation
+ // OtherError indicated any other error: don't cache these.
+ OtherError
)
// Classify classifies a message, it returns the Type.
diff --git a/middleware/pkg/storage/fs.go b/middleware/pkg/storage/fs.go
index 3ee14b7ed..4cbf526ae 100644
--- a/middleware/pkg/storage/fs.go
+++ b/middleware/pkg/storage/fs.go
@@ -25,7 +25,7 @@ type dir http.Dir
//
// CoreDir will default to "$HOME/.coredns" on Unix, but it's location can be overriden with the COREDNSPATH
// environment variable.
-var CoreDir dir = dir(fsPath())
+var CoreDir = dir(fsPath())
func (d dir) Zone(z string) dir {
if z != "." && z[len(z)-2] == '.' {
diff --git a/middleware/pkg/storage/fs_test.go b/middleware/pkg/storage/fs_test.go
index f7e8ccf9d..5692b580e 100644
--- a/middleware/pkg/storage/fs_test.go
+++ b/middleware/pkg/storage/fs_test.go
@@ -7,7 +7,7 @@ import (
"testing"
)
-func TestfsPath(t *testing.T) {
+func TestFsPath(t *testing.T) {
if actual := fsPath(); !strings.HasSuffix(actual, ".coredns") {
t.Errorf("Expected path to be a .coredns folder, got: %v", actual)
}
diff --git a/middleware/pprof/pprof.go b/middleware/pprof/pprof.go
index f538b3091..cbef104d3 100644
--- a/middleware/pprof/pprof.go
+++ b/middleware/pprof/pprof.go
@@ -13,13 +13,14 @@ type Handler struct {
}
func (h *Handler) Startup() error {
- if ln, err := net.Listen("tcp", addr); err != nil {
+ ln, err := net.Listen("tcp", addr)
+ if err != nil {
log.Printf("[ERROR] Failed to start pprof handler: %s", err)
return err
- } else {
- h.ln = ln
}
+ h.ln = ln
+
h.mux = http.NewServeMux()
h.mux.HandleFunc(path+"/", pp.Index)
h.mux.HandleFunc(path+"/cmdline", pp.Cmdline)
diff --git a/middleware/secondary/setup.go b/middleware/secondary/setup.go
index d0367094d..eb112faf9 100644
--- a/middleware/secondary/setup.go
+++ b/middleware/secondary/setup.go
@@ -56,7 +56,7 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) {
if len(args) > 0 {
origins = args
}
- for i, _ := range origins {
+ for i := range origins {
origins[i] = middleware.Host(origins[i]).Normalize()
z[origins[i]] = file.NewZone(origins[i], "stdin")
names = append(names, origins[i])
diff --git a/middleware/test/helpers.go b/middleware/test/helpers.go
index 8ed27261f..37d046cb3 100644
--- a/middleware/test/helpers.go
+++ b/middleware/test/helpers.go
@@ -149,12 +149,12 @@ func Section(t *testing.T, tc Case, sect Sect, rr []dns.RR) bool {
return false
}
if x.SignerName != section[i].(*dns.RRSIG).SignerName {
- t.Errorf("rr %d should have a SignerName of %d, but has %d", i, section[i].(*dns.RRSIG).SignerName, x.SignerName)
+ t.Errorf("rr %d should have a SignerName of %s, but has %s", i, section[i].(*dns.RRSIG).SignerName, x.SignerName)
return false
}
case *dns.NSEC:
if x.NextDomain != section[i].(*dns.NSEC).NextDomain {
- t.Errorf("rr %d should have a NextDomain of %d, but has %d", i, section[i].(*dns.NSEC).NextDomain, x.NextDomain)
+ t.Errorf("rr %d should have a NextDomain of %s, but has %s", i, section[i].(*dns.NSEC).NextDomain, x.NextDomain)
return false
}
// TypeBitMap