Fix ineffassign (#1959)

* Fix ineffassign

This fix tries to fix ineffassign, as was reported in:
https://goreportcard.com/report/github.com/coredns/coredns#ineffassign

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Update setup.go

Revert this one change, so this can be merged.
This commit is contained in:
Yong Tang
2018-07-28 17:32:13 +08:00
committed by Miek Gieben
parent 62df253371
commit 54ec78c1ba
8 changed files with 10 additions and 15 deletions

View File

@@ -50,7 +50,7 @@ func federationParse(c *caddy.Controller) (*Federation, error) {
for c.Next() {
// federation [zones..]
zones := c.RemainingArgs()
origins := []string{}
var origins []string
if len(zones) > 0 {
origins = make([]string, len(zones))
copy(origins, zones)

View File

@@ -53,7 +53,6 @@ func setup(c *caddy.Controller) error {
func fileParse(c *caddy.Controller) (Zones, error) {
z := make(map[string]*Zone)
names := []string{}
origins := []string{}
config := dnsserver.GetConfig(c)
@@ -64,7 +63,7 @@ func fileParse(c *caddy.Controller) (Zones, error) {
}
fileName := c.Val()
origins = make([]string, len(c.ServerBlockKeys))
origins := make([]string, len(c.ServerBlockKeys))
copy(origins, c.ServerBlockKeys)
args := c.RemainingArgs()
if len(args) > 0 {

View File

@@ -203,7 +203,7 @@ func (z *Zone) nameFromRight(qname string, i int) (string, bool) {
}
k := 0
shot := false
var shot bool
for j := 1; j <= i; j++ {
k, shot = dns.PrevLabel(qname, j+z.origLen)
if shot {

View File

@@ -125,7 +125,8 @@ func SplitHostPort(s string) (host, port string, ipnet *net.IPNet, err error) {
// Get the first lower octet boundary to see what encompassing zone we should be authoritative for.
mod := (bits - ones) % sizeDigit
nearest := (bits - ones) + mod
offset, end := 0, false
offset := 0
var end bool
for i := 0; i < nearest/sizeDigit; i++ {
offset, end = dns.NextLabel(rev, offset)
if end {

View File

@@ -71,7 +71,7 @@ func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
}
for {
start := time.Now()
reply := new(dns.Msg)
var reply *dns.Msg
var backendErr error
// Since Select() should give us "up" hosts, keep retrying

View File

@@ -70,7 +70,7 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
for {
start := time.Now()
reply := new(dns.Msg)
var reply *dns.Msg
var backendErr error
// Since Select() should give us "up" hosts, keep retrying

View File

@@ -49,13 +49,12 @@ func setup(c *caddy.Controller) error {
func secondaryParse(c *caddy.Controller) (file.Zones, error) {
z := make(map[string]*file.Zone)
names := []string{}
origins := []string{}
upstr := upstream.Upstream{}
for c.Next() {
if c.Val() == "secondary" {
// secondary [origin]
origins = make([]string, len(c.ServerBlockKeys))
origins := make([]string, len(c.ServerBlockKeys))
copy(origins, c.ServerBlockKeys)
args := c.RemainingArgs()
if len(args) > 0 {

View File

@@ -74,10 +74,8 @@ func TestReverse(t *testing.T) {
m := new(dns.Msg)
for i, tc := range tests {
inaddr := tc.addr
var err error
if !strings.HasSuffix(tc.addr, ".arpa.") {
inaddr, err = dns.ReverseAddr(tc.addr)
inaddr, err := dns.ReverseAddr(tc.addr)
if err != nil {
t.Fatalf("Test %d, failed to convert %s", i, tc.addr)
}
@@ -122,10 +120,8 @@ func TestReverseInAddr(t *testing.T) {
m := new(dns.Msg)
for i, tc := range tests {
inaddr := tc.addr
var err error
if !strings.HasSuffix(tc.addr, ".arpa.") {
inaddr, err = dns.ReverseAddr(tc.addr)
inaddr, err := dns.ReverseAddr(tc.addr)
if err != nil {
t.Fatalf("Test %d, failed to convert %s", i, tc.addr)
}