mirror of
https://github.com/coredns/coredns.git
synced 2025-12-07 19:05:19 -05:00
Golint2 (#280)
* Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * More lint fixes This leaves: ~~~ middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..." middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported ~~~ I plan on reworking the proxy anyway, so I'll leave that be.
This commit is contained in:
@@ -46,7 +46,7 @@ var delegationTestCases = []test.Case{
|
||||
}
|
||||
|
||||
func TestLookupDelegation(t *testing.T) {
|
||||
zone, err := Parse(strings.NewReader(dbMiekNL_delegation), testzone, "stdin")
|
||||
zone, err := Parse(strings.NewReader(dbMiekNLDelegation), testzone, "stdin")
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error when reading zone, got %q", err)
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func TestLookupDelegation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
const dbMiekNL_delegation = `
|
||||
const dbMiekNLDelegation = `
|
||||
$TTL 30M
|
||||
$ORIGIN miek.nl.
|
||||
@ IN SOA linode.atoom.net. miek.miek.nl. (
|
||||
|
||||
@@ -105,7 +105,7 @@ var dnssecTestCases = []test.Case{
|
||||
}
|
||||
|
||||
func TestLookupDNSSEC(t *testing.T) {
|
||||
zone, err := Parse(strings.NewReader(dbMiekNL_signed), testzone, "stdin")
|
||||
zone, err := Parse(strings.NewReader(dbMiekNLSigned), testzone, "stdin")
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error when reading zone, got %q", err)
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func TestLookupDNSSEC(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkLookupDNSSEC(b *testing.B) {
|
||||
zone, err := Parse(strings.NewReader(dbMiekNL_signed), testzone, "stdin")
|
||||
zone, err := Parse(strings.NewReader(dbMiekNLSigned), testzone, "stdin")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func BenchmarkLookupDNSSEC(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
const dbMiekNL_signed = `
|
||||
const dbMiekNLSigned = `
|
||||
; File written on Sun Mar 27 04:13:01 2016
|
||||
; dnssec_signzone version 9.10.3-P4-Ubuntu
|
||||
miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. (
|
||||
|
||||
@@ -13,17 +13,20 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// File is the middleware that reads zone data from disk.
|
||||
File struct {
|
||||
Next middleware.Handler
|
||||
Zones Zones
|
||||
}
|
||||
|
||||
// Zones maps zone names to a *Zone.
|
||||
Zones struct {
|
||||
Z map[string]*Zone
|
||||
Names []string
|
||||
}
|
||||
)
|
||||
|
||||
// ServeDNS implements the middleware.Handle interface.
|
||||
func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := request.Request{W: w, Req: r}
|
||||
|
||||
|
||||
@@ -10,10 +10,15 @@ import (
|
||||
type Result int
|
||||
|
||||
const (
|
||||
// Success is a successful lookup.
|
||||
Success Result = iota
|
||||
// NameError indicates a nameerror
|
||||
NameError
|
||||
// Delegation indicates the lookup resulted in a delegation.
|
||||
Delegation
|
||||
// NoData indicates the lookup resulted in a NODATA.
|
||||
NoData
|
||||
// ServerFailure indicates a server failure during the lookup.
|
||||
ServerFailure
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func TestParseNSEC3PARAM(t *testing.T) {
|
||||
_, err := Parse(strings.NewReader(nsec3param_test), "miek.nl", "stdin")
|
||||
_, err := Parse(strings.NewReader(nsec3paramTest), "miek.nl", "stdin")
|
||||
if err == nil {
|
||||
t.Fatalf("expected error when reading zone, got nothing")
|
||||
}
|
||||
@@ -14,17 +14,17 @@ func TestParseNSEC3PARAM(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseNSEC3(t *testing.T) {
|
||||
_, err := Parse(strings.NewReader(nsec3_test), "miek.nl", "stdin")
|
||||
_, err := Parse(strings.NewReader(nsec3Test), "miek.nl", "stdin")
|
||||
if err == nil {
|
||||
t.Fatalf("expected error when reading zone, got nothing")
|
||||
}
|
||||
t.Logf("%v\n", err)
|
||||
}
|
||||
|
||||
const nsec3param_test = `miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1460175181 14400 3600 604800 14400
|
||||
const nsec3paramTest = `miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1460175181 14400 3600 604800 14400
|
||||
miek.nl. 1800 IN NS omval.tednet.nl.
|
||||
miek.nl. 0 IN NSEC3PARAM 1 0 5 A3DEBC9CC4F695C7`
|
||||
|
||||
const nsec3_test = `example.org. 1800 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082508 7200 3600 1209600 3600
|
||||
const nsec3Test = `example.org. 1800 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082508 7200 3600 1209600 3600
|
||||
aub8v9ce95ie18spjubsr058h41n7pa5.example.org. 284 IN NSEC3 1 1 5 D0CBEAAF0AC77314 AUB95P93VPKP55G6U5S4SGS7LS61ND85 NS SOA TXT RRSIG DNSKEY NSEC3PARAM
|
||||
aub8v9ce95ie18spjubsr058h41n7pa5.example.org. 284 IN RRSIG NSEC3 8 2 600 20160910232502 20160827231002 14028 example.org. XBNpA7KAIjorPbXvTinOHrc1f630aHic2U716GHLHA4QMx9cl9ss4QjR Wj2UpDM9zBW/jNYb1xb0yjQoez/Jv200w0taSWjRci5aUnRpOi9bmcrz STHb6wIUjUsbJ+NstQsUwVkj6679UviF1FqNwr4GlJnWG3ZrhYhE+NI6 s0k=`
|
||||
|
||||
@@ -178,7 +178,6 @@ Restart:
|
||||
}
|
||||
}
|
||||
|
||||
// The maximum difference between two serial numbers. If the difference between
|
||||
// two serials is greater than this number, the smaller one is considered
|
||||
// greater.
|
||||
// MaxSerialIncrement is the maximum difference between two serial numbers. If the difference between
|
||||
// two serials is greater than this number, the smaller one is considered greater.
|
||||
const MaxSerialIncrement uint32 = 2147483647
|
||||
|
||||
@@ -70,7 +70,7 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||
return Zones{}, err
|
||||
}
|
||||
|
||||
for i, _ := range origins {
|
||||
for i := range origins {
|
||||
origins[i] = middleware.Host(origins[i]).Normalize()
|
||||
zone, err := Parse(reader, origins[i], fileName)
|
||||
if err == nil {
|
||||
@@ -116,7 +116,7 @@ func TransferParse(c *caddy.Controller) (tos, froms []string, err error) {
|
||||
case "transfer":
|
||||
if value == "to" {
|
||||
tos = c.RemainingArgs()
|
||||
for i, _ := range tos {
|
||||
for i := range tos {
|
||||
if tos[i] != "*" {
|
||||
if x := net.ParseIP(tos[i]); x == nil {
|
||||
return nil, nil, fmt.Errorf("must specify an IP addres: `%s'", tos[i])
|
||||
@@ -127,7 +127,7 @@ func TransferParse(c *caddy.Controller) (tos, froms []string, err error) {
|
||||
}
|
||||
if value == "from" {
|
||||
froms = c.RemainingArgs()
|
||||
for i, _ := range froms {
|
||||
for i := range froms {
|
||||
if froms[i] != "*" {
|
||||
if x := net.ParseIP(froms[i]); x == nil {
|
||||
return nil, nil, fmt.Errorf("must specify an IP addres: `%s'", froms[i])
|
||||
|
||||
@@ -2,6 +2,7 @@ package tree
|
||||
|
||||
import "github.com/miekg/dns"
|
||||
|
||||
// Elem is an element in the tree.
|
||||
type Elem struct {
|
||||
m map[uint16][]dns.RR
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@ package tree
|
||||
import "github.com/miekg/dns"
|
||||
|
||||
const (
|
||||
TD234 = iota
|
||||
BU23
|
||||
td234 = iota
|
||||
bu23
|
||||
)
|
||||
|
||||
// Result is a result of a Search.
|
||||
type Result int
|
||||
|
||||
// Various constants that indicated the type a resource returned.
|
||||
const (
|
||||
Found Result = iota
|
||||
NameError
|
||||
@@ -34,10 +35,10 @@ const (
|
||||
)
|
||||
|
||||
// Operation mode of the LLRB tree.
|
||||
const Mode = BU23
|
||||
const mode = bu23
|
||||
|
||||
func init() {
|
||||
if Mode != TD234 && Mode != BU23 {
|
||||
if mode != td234 && mode != bu23 {
|
||||
panic("tree: unknown mode")
|
||||
}
|
||||
}
|
||||
@@ -48,8 +49,8 @@ type Color bool
|
||||
const (
|
||||
// Red as false give us the defined behaviour that new nodes are red. Although this
|
||||
// is incorrect for the root node, that is resolved on the first insertion.
|
||||
Red Color = false
|
||||
Black Color = true
|
||||
red Color = false
|
||||
black Color = true
|
||||
)
|
||||
|
||||
// A Node represents a node in the LLRB tree.
|
||||
@@ -70,7 +71,7 @@ type Tree struct {
|
||||
// color returns the effect color of a Node. A nil node returns black.
|
||||
func (n *Node) color() Color {
|
||||
if n == nil {
|
||||
return Black
|
||||
return black
|
||||
}
|
||||
return n.Color
|
||||
}
|
||||
@@ -82,7 +83,7 @@ func (n *Node) rotateLeft() (root *Node) {
|
||||
n.Right = root.Left
|
||||
root.Left = n
|
||||
root.Color = n.Color
|
||||
n.Color = Red
|
||||
n.Color = red
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ func (n *Node) rotateRight() (root *Node) {
|
||||
n.Left = root.Right
|
||||
root.Right = n
|
||||
root.Color = n.Color
|
||||
n.Color = Red
|
||||
n.Color = red
|
||||
return
|
||||
}
|
||||
|
||||
@@ -108,16 +109,16 @@ func (n *Node) flipColors() {
|
||||
// fixUp ensures that black link balance is correct, that red nodes lean left,
|
||||
// and that 4 nodes are split in the case of BU23 and properly balanced in TD234.
|
||||
func (n *Node) fixUp() *Node {
|
||||
if n.Right.color() == Red {
|
||||
if Mode == TD234 && n.Right.Left.color() == Red {
|
||||
if n.Right.color() == red {
|
||||
if mode == td234 && n.Right.Left.color() == red {
|
||||
n.Right = n.Right.rotateRight()
|
||||
}
|
||||
n = n.rotateLeft()
|
||||
}
|
||||
if n.Left.color() == Red && n.Left.Left.color() == Red {
|
||||
if n.Left.color() == red && n.Left.Left.color() == red {
|
||||
n = n.rotateRight()
|
||||
}
|
||||
if Mode == BU23 && n.Left.color() == Red && n.Right.color() == Red {
|
||||
if mode == bu23 && n.Left.color() == red && n.Right.color() == red {
|
||||
n.flipColors()
|
||||
}
|
||||
return n
|
||||
@@ -125,11 +126,11 @@ func (n *Node) fixUp() *Node {
|
||||
|
||||
func (n *Node) moveRedLeft() *Node {
|
||||
n.flipColors()
|
||||
if n.Right.Left.color() == Red {
|
||||
if n.Right.Left.color() == red {
|
||||
n.Right = n.Right.rotateRight()
|
||||
n = n.rotateLeft()
|
||||
n.flipColors()
|
||||
if Mode == TD234 && n.Right.Right.color() == Red {
|
||||
if mode == td234 && n.Right.Right.color() == red {
|
||||
n.Right = n.Right.rotateLeft()
|
||||
}
|
||||
}
|
||||
@@ -138,7 +139,7 @@ func (n *Node) moveRedLeft() *Node {
|
||||
|
||||
func (n *Node) moveRedRight() *Node {
|
||||
n.flipColors()
|
||||
if n.Left.Left.color() == Red {
|
||||
if n.Left.Left.color() == red {
|
||||
n = n.rotateRight()
|
||||
n.flipColors()
|
||||
}
|
||||
@@ -212,7 +213,7 @@ func (t *Tree) Insert(rr dns.RR) {
|
||||
var d int
|
||||
t.Root, d = t.Root.insert(rr)
|
||||
t.Count += d
|
||||
t.Root.Color = Black
|
||||
t.Root.Color = black
|
||||
}
|
||||
|
||||
func (n *Node) insert(rr dns.RR) (root *Node, d int) {
|
||||
@@ -223,8 +224,8 @@ func (n *Node) insert(rr dns.RR) (root *Node, d int) {
|
||||
return n, 1
|
||||
}
|
||||
|
||||
if Mode == TD234 {
|
||||
if n.Left.color() == Red && n.Right.color() == Red {
|
||||
if mode == td234 {
|
||||
if n.Left.color() == red && n.Right.color() == red {
|
||||
n.flipColors()
|
||||
}
|
||||
}
|
||||
@@ -238,15 +239,15 @@ func (n *Node) insert(rr dns.RR) (root *Node, d int) {
|
||||
n.Right, d = n.Right.insert(rr)
|
||||
}
|
||||
|
||||
if n.Right.color() == Red && n.Left.color() == Black {
|
||||
if n.Right.color() == red && n.Left.color() == black {
|
||||
n = n.rotateLeft()
|
||||
}
|
||||
if n.Left.color() == Red && n.Left.Left.color() == Red {
|
||||
if n.Left.color() == red && n.Left.Left.color() == red {
|
||||
n = n.rotateRight()
|
||||
}
|
||||
|
||||
if Mode == BU23 {
|
||||
if n.Left.color() == Red && n.Right.color() == Red {
|
||||
if mode == bu23 {
|
||||
if n.Left.color() == red && n.Right.color() == red {
|
||||
n.flipColors()
|
||||
}
|
||||
}
|
||||
@@ -267,14 +268,14 @@ func (t *Tree) DeleteMin() {
|
||||
if t.Root == nil {
|
||||
return
|
||||
}
|
||||
t.Root.Color = Black
|
||||
t.Root.Color = black
|
||||
}
|
||||
|
||||
func (n *Node) deleteMin() (root *Node, d int) {
|
||||
if n.Left == nil {
|
||||
return nil, -1
|
||||
}
|
||||
if n.Left.color() == Black && n.Left.Left.color() == Black {
|
||||
if n.Left.color() == black && n.Left.Left.color() == black {
|
||||
n = n.moveRedLeft()
|
||||
}
|
||||
n.Left, d = n.Left.deleteMin()
|
||||
@@ -295,17 +296,17 @@ func (t *Tree) DeleteMax() {
|
||||
if t.Root == nil {
|
||||
return
|
||||
}
|
||||
t.Root.Color = Black
|
||||
t.Root.Color = black
|
||||
}
|
||||
|
||||
func (n *Node) deleteMax() (root *Node, d int) {
|
||||
if n.Left != nil && n.Left.color() == Red {
|
||||
if n.Left != nil && n.Left.color() == red {
|
||||
n = n.rotateRight()
|
||||
}
|
||||
if n.Right == nil {
|
||||
return nil, -1
|
||||
}
|
||||
if n.Right.color() == Black && n.Right.Left.color() == Black {
|
||||
if n.Right.color() == black && n.Right.Left.color() == black {
|
||||
n = n.moveRedRight()
|
||||
}
|
||||
n.Right, d = n.Right.deleteMax()
|
||||
@@ -345,26 +346,26 @@ func (t *Tree) DeleteNode(rr dns.RR) {
|
||||
if t.Root == nil {
|
||||
return
|
||||
}
|
||||
t.Root.Color = Black
|
||||
t.Root.Color = black
|
||||
}
|
||||
|
||||
func (n *Node) delete(rr dns.RR) (root *Node, d int) {
|
||||
if Less(n.Elem, rr.Header().Name) < 0 {
|
||||
if n.Left != nil {
|
||||
if n.Left.color() == Black && n.Left.Left.color() == Black {
|
||||
if n.Left.color() == black && n.Left.Left.color() == black {
|
||||
n = n.moveRedLeft()
|
||||
}
|
||||
n.Left, d = n.Left.delete(rr)
|
||||
}
|
||||
} else {
|
||||
if n.Left.color() == Red {
|
||||
if n.Left.color() == red {
|
||||
n = n.rotateRight()
|
||||
}
|
||||
if n.Right == nil && Less(n.Elem, rr.Header().Name) == 0 {
|
||||
return nil, -1
|
||||
}
|
||||
if n.Right != nil {
|
||||
if n.Right.color() == Black && n.Right.Left.color() == Black {
|
||||
if n.Right.color() == black && n.Right.Left.color() == black {
|
||||
n = n.moveRedRight()
|
||||
}
|
||||
if Less(n.Elem, rr.Header().Name) == 0 {
|
||||
|
||||
@@ -46,7 +46,7 @@ var wildcardTestCases = []test.Case{
|
||||
}
|
||||
|
||||
func TestLookupWildcard(t *testing.T) {
|
||||
zone, err := Parse(strings.NewReader(dbDnssexNL_signed), testzone1, "stdin")
|
||||
zone, err := Parse(strings.NewReader(dbDnssexNLSigned), testzone1, "stdin")
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error when reading zone, got %q", err)
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func TestLookupWildcard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
const dbDnssexNL_signed = `
|
||||
const dbDnssexNLSigned = `
|
||||
; File written on Tue Mar 29 21:02:24 2016
|
||||
; dnssec_signzone version 9.10.3-P4-Ubuntu
|
||||
dnssex.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. (
|
||||
|
||||
@@ -10,13 +10,12 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type (
|
||||
Xfr struct {
|
||||
*Zone
|
||||
}
|
||||
)
|
||||
// Xfr serves up an AXFR.
|
||||
type Xfr struct {
|
||||
*Zone
|
||||
}
|
||||
|
||||
// Serve an AXFR (and fallback of IXFR) as well.
|
||||
// ServeDNS implements the middleware.Handler interface.
|
||||
func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := request.Request{W: w, Req: r}
|
||||
if !x.TransferAllowed(state) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// Zone defines a structure that contains all data related to a DNS zone.
|
||||
type Zone struct {
|
||||
origin string
|
||||
file string
|
||||
@@ -31,6 +32,7 @@ type Zone struct {
|
||||
// TODO: shutdown watcher channel
|
||||
}
|
||||
|
||||
// Apex contains the apex records of a zone: SOA, NS and their potential signatures.
|
||||
type Apex struct {
|
||||
SOA *dns.SOA
|
||||
NS []dns.RR
|
||||
@@ -135,6 +137,7 @@ func (z *Zone) All() []dns.RR {
|
||||
return append([]dns.RR{z.Apex.SOA}, records...)
|
||||
}
|
||||
|
||||
// Reload reloads a zone when it is changed on disk. If z.NoRoload is true, no reloading will be done.
|
||||
func (z *Zone) Reload(shutdown chan bool) error {
|
||||
if z.NoReload {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user