Run golint and go vet (#276)

Cleanup the errors and removed deadcode along the way. The leaves
some error laying around, mostly about commenting exported identifier.
We should look hard if those really are needed.
This commit is contained in:
Miek Gieben
2016-09-21 17:01:19 +01:00
committed by GitHub
parent 7b79458c8a
commit 5301c5af5f
25 changed files with 60 additions and 386 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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)

View File

@@ -176,7 +176,6 @@ Restart:
}
}
}
return nil
}
// The maximum difference between two serial numbers. If the difference between

View File

@@ -39,7 +39,6 @@ func less(a, b string) int {
i++
aj, bj = ai, bi
}
return 0
}
func doDDD(b []byte) {

View File

@@ -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 {

View File

@@ -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)

View File

@@ -30,7 +30,7 @@ type Metrics struct {
Addr string
ln net.Listener
mux *http.ServeMux
Once sync.Once
Once *sync.Once
ZoneNames []string
}

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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] == '.' {

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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])

View File

@@ -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