From 1ad950f1775bdbf947f9ef118ca2dc11f296378b Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 27 Mar 2015 01:12:16 +0000 Subject: [PATCH] cosmetic: more linting --- nameserver/cache.go | 8 ++++---- nameserver/cache_test.go | 36 ++++++++++++++++++------------------ nameserver/dns.go | 10 +++++----- nameserver/http.go | 2 +- nameserver/http_test.go | 16 ++++++++-------- nameserver/mdns_lookup.go | 7 +++---- nameserver/mdns_server.go | 6 ++---- nameserver/server.go | 22 +++++++++++----------- nameserver/server_test.go | 28 ++++++++++++++-------------- nameserver/zone.go | 22 ++++++++-------------- weavedns/main.go | 4 ++-- 11 files changed, 76 insertions(+), 85 deletions(-) diff --git a/nameserver/cache.go b/nameserver/cache.go index bf24d4c4..fc7db41c 100644 --- a/nameserver/cache.go +++ b/nameserver/cache.go @@ -150,14 +150,14 @@ func (e *cacheEntry) setReply(reply *dns.Msg, flags uint8, now time.Time) bool { e.validUntil = now.Add(time.Second * time.Duration(negLocalTTL)) } else { // calculate the validUntil from the reply TTL - var minTtl uint32 = math.MaxUint32 + var minTTL uint32 = math.MaxUint32 for _, rr := range reply.Answer { ttl := rr.Header().Ttl - if ttl < minTtl { - minTtl = ttl // TODO: improve the minTTL calculation (maybe we should skip some RRs) + if ttl < minTTL { + minTTL = ttl // TODO: improve the minTTL calculation (maybe we should skip some RRs) } } - e.validUntil = now.Add(time.Second * time.Duration(minTtl)) + e.validUntil = now.Add(time.Second * time.Duration(minTTL)) } if reply != nil { diff --git a/nameserver/cache_test.go b/nameserver/cache_test.go index f5549df9..bccb8d32 100644 --- a/nameserver/cache_test.go +++ b/nameserver/cache_test.go @@ -66,14 +66,14 @@ func TestCacheEntries(t *testing.T) { question := &questionMsg.Question[0] t.Logf("Trying to get a name") - resp, err := l.Get(questionMsg, minUdpSize, time.Now()) + resp, err := l.Get(questionMsg, minUDPSize, time.Now()) wt.AssertNoErr(t, err) if resp != nil { t.Logf("Got '%s'", resp) t.Fatalf("ERROR: Did not expect a reponse from Get() yet") } t.Logf("Trying to get it again") - resp, err = l.Get(questionMsg, minUdpSize, time.Now()) + resp, err = l.Get(questionMsg, minUDPSize, time.Now()) wt.AssertNoErr(t, err) if resp != nil { t.Logf("Got '%s'", resp) @@ -86,7 +86,7 @@ func TestCacheEntries(t *testing.T) { timeGet1 := time.Now() t.Logf("Checking we can Get() the reply now") - resp, err = l.Get(questionMsg, minUdpSize, timeGet1) + resp, err = l.Get(questionMsg, minUDPSize, timeGet1) wt.AssertNoErr(t, err) wt.AssertTrue(t, resp != nil, "reponse from Get()") t.Logf("Received '%s'", resp.Answer[0]) @@ -94,7 +94,7 @@ func TestCacheEntries(t *testing.T) { ttlGet1 := resp.Answer[0].Header().Ttl t.Logf("Checking a Wait() with timeout=0 gets the same result") - resp, err = l.Wait(questionMsg, time.Duration(0)*time.Second, minUdpSize, time.Now()) + resp, err = l.Wait(questionMsg, time.Duration(0)*time.Second, minUDPSize, time.Now()) wt.AssertNoErr(t, err) wt.AssertTrue(t, resp != nil, "reponse from a Wait(timeout=0)") t.Logf("Received '%s'", resp.Answer[0]) @@ -102,7 +102,7 @@ func TestCacheEntries(t *testing.T) { timeGet2 := timeGet1.Add(time.Duration(1) * time.Second) t.Logf("Checking that a second Get(), after 1 second, gets the same result, but with reduced TTL") - resp, err = l.Get(questionMsg, minUdpSize, timeGet2) + resp, err = l.Get(questionMsg, minUDPSize, timeGet2) wt.AssertNoErr(t, err) wt.AssertTrue(t, resp != nil, "reponse from a second Get()") t.Logf("Received '%s'", resp.Answer[0]) @@ -112,7 +112,7 @@ func TestCacheEntries(t *testing.T) { timeGet3 := timeGet1.Add(time.Duration(localTTL) * time.Second) t.Logf("Checking that a third Get(), after %d second, gets no result", localTTL) - resp, err = l.Get(questionMsg, minUdpSize, timeGet3) + resp, err = l.Get(questionMsg, minUDPSize, timeGet3) wt.AssertNoErr(t, err) if resp != nil { t.Logf("Got '%s'", resp) @@ -128,7 +128,7 @@ func TestCacheEntries(t *testing.T) { l.Remove(question) // do it again: should have no effect... wt.AssertEqualInt(t, l.Len(), lenBefore-1, "cache length") - resp, err = l.Get(questionMsg, minUdpSize, timeGet1) + resp, err = l.Get(questionMsg, minUDPSize, timeGet1) wt.AssertNoErr(t, err) wt.AssertTrue(t, resp == nil, "reponse from the Get() after a Remove()") @@ -141,7 +141,7 @@ func TestCacheEntries(t *testing.T) { l.Put(questionMsg, reply3, 0, timePut3) t.Logf("Checking we get the last one...") - resp, err = l.Get(questionMsg, minUdpSize, timePut3) + resp, err = l.Get(questionMsg, minUDPSize, timePut3) wt.AssertNoErr(t, err) wt.AssertTrue(t, resp != nil, "reponse from the Get()") t.Logf("Received '%s'", resp.Answer[0]) @@ -149,7 +149,7 @@ func TestCacheEntries(t *testing.T) { wt.AssertEqualString(t, resp.Answer[0].(*dns.A).A.String(), "10.0.1.3", "IP address") wt.AssertEqualInt(t, int(resp.Answer[0].Header().Ttl), int(localTTL), "TTL") - resp, err = l.Get(questionMsg, minUdpSize, timePut3.Add(time.Duration(localTTL-1)*time.Second)) + resp, err = l.Get(questionMsg, minUDPSize, timePut3.Add(time.Duration(localTTL-1)*time.Second)) wt.AssertNoErr(t, err) wt.AssertTrue(t, resp != nil, "reponse from the Get()") t.Logf("Received '%s'", resp.Answer[0]) @@ -159,7 +159,7 @@ func TestCacheEntries(t *testing.T) { t.Logf("Checking we get empty replies when they are expired...") lenBefore = l.Len() - resp, err = l.Get(questionMsg, minUdpSize, timePut3.Add(time.Duration(localTTL)*time.Second)) + resp, err = l.Get(questionMsg, minUDPSize, timePut3.Add(time.Duration(localTTL)*time.Second)) wt.AssertNoErr(t, err) if resp != nil { t.Logf("Received '%s'", resp.Answer[0]) @@ -173,7 +173,7 @@ func TestCacheEntries(t *testing.T) { question2 := &questionMsg2.Question[0] t.Logf("Trying to Get() a name") - resp, err = l.Get(questionMsg2, minUdpSize, time.Now()) + resp, err = l.Get(questionMsg2, minUDPSize, time.Now()) wt.AssertNoErr(t, err) wt.AssertNil(t, resp, "reponse from Get() yet") @@ -181,10 +181,10 @@ func TestCacheEntries(t *testing.T) { replyTemp2 := makeAddressReply(questionMsg2, question2, []net.IP{net.ParseIP("10.0.9.9")}) l.Remove(question2) l.Put(questionMsg2, replyTemp2, 0, time.Now()) - resp, err = l.Get(questionMsg2, minUdpSize, time.Now()) + resp, err = l.Get(questionMsg2, minUDPSize, time.Now()) wt.AssertNoErr(t, err) wt.AssertNotNil(t, resp, "reponse from Get()") - resp, err = l.Wait(questionMsg2, time.Duration(0)*time.Second, minUdpSize, time.Now()) + resp, err = l.Wait(questionMsg2, time.Duration(0)*time.Second, minUDPSize, time.Now()) wt.AssertNoErr(t, err) wt.AssertNotNil(t, resp, "reponse from Get()") @@ -196,13 +196,13 @@ func TestCacheEntries(t *testing.T) { t.Logf("Checking that a entry with CacheNoLocalReplies return an error") timePut3 = time.Now() l.Put(questionMsg3, nil, CacheNoLocalReplies, timePut3) - resp, err = l.Get(questionMsg3, minUdpSize, timePut3) + resp, err = l.Get(questionMsg3, minUDPSize, timePut3) wt.AssertNil(t, resp, "Get() response with CacheNoLocalReplies") wt.AssertNotNil(t, err, "Get() error with CacheNoLocalReplies") timeExpiredGet3 := timePut3.Add(time.Second * time.Duration(negLocalTTL+1)) t.Logf("Checking that we get an expired response after %f seconds", timeExpiredGet3.Sub(timePut3).Seconds()) - resp, err = l.Get(questionMsg3, minUdpSize, timeExpiredGet3) + resp, err = l.Get(questionMsg3, minUDPSize, timeExpiredGet3) wt.AssertNil(t, resp, "expired Get() response with CacheNoLocalReplies") wt.AssertNil(t, err, "expired Get() error with CacheNoLocalReplies") @@ -210,7 +210,7 @@ func TestCacheEntries(t *testing.T) { t.Logf("Checking that Put&Get with CacheNoLocalReplies with a Remove in the middle returns nothing") l.Put(questionMsg3, nil, CacheNoLocalReplies, time.Now()) l.Remove(question3) - resp, err = l.Get(questionMsg3, minUdpSize, time.Now()) + resp, err = l.Get(questionMsg3, minUDPSize, time.Now()) wt.AssertNil(t, resp, "Get() reponse with CacheNoLocalReplies") wt.AssertNil(t, err, "Get() error with CacheNoLocalReplies") } @@ -237,10 +237,10 @@ func TestCacheBlockingOps(t *testing.T) { go func(request *dns.Msg) { t.Logf("Querying about %s...", request.Question[0].Name) - _, err := l.Get(request, minUdpSize, time.Now()) + _, err := l.Get(request, minUDPSize, time.Now()) wt.AssertNoErr(t, err) t.Logf("Waiting for %s...", request.Question[0].Name) - r, err := l.Wait(request, 1*time.Second, minUdpSize, time.Now()) + r, err := l.Wait(request, 1*time.Second, minUDPSize, time.Now()) t.Logf("Obtained response for %s:\n%s", request.Question[0].Name, r) wt.AssertNoErr(t, err) }(questionMsg) diff --git a/nameserver/dns.go b/nameserver/dns.go index 2de4493b..0ef0a52e 100644 --- a/nameserver/dns.go +++ b/nameserver/dns.go @@ -8,8 +8,8 @@ import ( const ( localTTL uint32 = 30 // somewhat arbitrary; we don't expect anyone downstream to cache results negLocalTTL = 30 // TTL for negative local resolutions - minUdpSize = 512 - maxUdpSize = 65535 + minUDPSize = 512 + maxUDPSize = 65535 ) func makeHeader(r *dns.Msg, q *dns.Question) *dns.RR_Header { @@ -82,9 +82,9 @@ func makeDNSNotImplResponse(r *dns.Msg) *dns.Msg { // get the maximum UDP-reply length func getMaxReplyLen(r *dns.Msg, proto dnsProtocol) int { - maxLen := minUdpSize - if proto == protTcp { - maxLen = maxUdpSize + maxLen := minUDPSize + if proto == protTCP { + maxLen = maxUDPSize } else if opt := r.IsEdns0(); opt != nil { maxLen = int(opt.UDPSize()) } diff --git a/nameserver/http.go b/nameserver/http.go index aa07ab2d..db15275e 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -17,7 +17,7 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, level.Printf("[http] "+logmsg, logargs...) } -func ListenHttp(version string, server *DNSServer, domain string, db Zone, port int) { +func ListenHTTP(version string, server *DNSServer, domain string, db Zone, port int) { muxRouter := mux.NewRouter() diff --git a/nameserver/http_test.go b/nameserver/http_test.go index 6a72b6c6..196c8447 100644 --- a/nameserver/http_test.go +++ b/nameserver/http_test.go @@ -30,14 +30,14 @@ func TestHttp(t *testing.T) { var zone = new(ZoneDb) port := rand.Intn(10000) + 32768 fmt.Println("Http test on port", port) - go ListenHttp("", nil, testDomain, zone, port) + go ListenHTTP("", nil, testDomain, zone, port) time.Sleep(100 * time.Millisecond) // Allow for http server to get going // Ask the http server to add our test address into the database addrParts := strings.Split(testAddr1, "/") - addrUrl := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, containerID, addrParts[0]) - resp, err := genForm("PUT", addrUrl, + addrURL := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, containerID, addrParts[0]) + resp, err := genForm("PUT", addrURL, url.Values{"fqdn": {successTestName}, "local_ip": {dockerIP}, "routing_prefix": {addrParts[1]}}) wt.AssertNoErr(t, err) wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response") @@ -51,21 +51,21 @@ func TestHttp(t *testing.T) { } // Adding exactly the same address should be OK - resp, err = genForm("PUT", addrUrl, + resp, err = genForm("PUT", addrURL, url.Values{"fqdn": {successTestName}, "local_ip": {dockerIP}, "routing_prefix": {addrParts[1]}}) wt.AssertNoErr(t, err) wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http success response for duplicate add") // Now try adding the same address again with a different ident -- // again should be fine - otherUrl := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, "other", addrParts[0]) - resp, err = genForm("PUT", otherUrl, + otherURL := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, "other", addrParts[0]) + resp, err = genForm("PUT", otherURL, url.Values{"fqdn": {successTestName}, "local_ip": {dockerIP}, "routing_prefix": {addrParts[1]}}) wt.AssertNoErr(t, err) wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response") // Delete the address - resp, err = genForm("DELETE", addrUrl, nil) + resp, err = genForm("DELETE", addrURL, nil) wt.AssertNoErr(t, err) wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response") @@ -74,7 +74,7 @@ func TestHttp(t *testing.T) { wt.AssertNoErr(t, err) // Delete the address record mentioning the other container - resp, err = genForm("DELETE", otherUrl, nil) + resp, err = genForm("DELETE", otherURL, nil) wt.AssertNoErr(t, err) wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response") diff --git a/nameserver/mdns_lookup.go b/nameserver/mdns_lookup.go index 245133e2..ddfb022e 100644 --- a/nameserver/mdns_lookup.go +++ b/nameserver/mdns_lookup.go @@ -14,11 +14,10 @@ func mdnsLookup(client *MDNSClient, name string, qtype uint16) (*Response, error Debug.Printf("[mdns] Error for query type %s name %s: %s", dns.TypeToString[qtype], name, err) return nil, err - } else { - Debug.Printf("[mdns] Got response name for query type %s name %s: name %s, addr %s", - dns.TypeToString[qtype], name, resp.Name, resp.Addr) - return resp, nil } + Debug.Printf("[mdns] Got response name for query type %s name %s: name %s, addr %s", + dns.TypeToString[qtype], name, resp.Name, resp.Addr) + return resp, nil } return nil, LookupError(name) } diff --git a/nameserver/mdns_server.go b/nameserver/mdns_server.go index 2c7f5cbb..f576817f 100644 --- a/nameserver/mdns_server.go +++ b/nameserver/mdns_server.go @@ -55,18 +55,16 @@ func (s *MDNSServer) Start(ifi *net.Interface, localDomain string) error { func(zone Lookup, r *dns.Msg, q *dns.Question) *dns.Msg { if ip, err := zone.LookupName(q.Name); err == nil { return makeAddressReply(r, q, []net.IP{ip}) - } else { - return nil } + return nil }) handleReverse := s.makeHandler(dns.TypePTR, func(zone Lookup, r *dns.Msg, q *dns.Question) *dns.Msg { if name, err := zone.LookupInaddr(q.Name); err == nil { return makePTRReply(r, q, []string{name}) - } else { - return nil } + return nil }) mux := dns.NewServeMux() diff --git a/nameserver/server.go b/nameserver/server.go index ab15c559..05aaaac8 100644 --- a/nameserver/server.go +++ b/nameserver/server.go @@ -36,21 +36,21 @@ type DNSServerConfig struct { // (Optional) timeout for DNS queries Timeout int // (Optional) UDP buffer length - UdpBufLen int + UDPBufLen int } type dnsProtocol uint8 const ( - protUdp dnsProtocol = iota // UDP protocol - protTcp dnsProtocol = iota // TCP protocol + protUDP dnsProtocol = iota // UDP protocol + protTCP dnsProtocol = iota // TCP protocol ) func (proto dnsProtocol) String() string { switch proto { - case protUdp: + case protUDP: return "UDP" - case protTcp: + case protTCP: return "TCP" } return "unknown" @@ -59,9 +59,9 @@ func (proto dnsProtocol) String() string { // get a new dns.Client for a protocol func (proto dnsProtocol) GetNewClient(bufsize int) *dns.Client { switch proto { - case protTcp: + case protTCP: return &dns.Client{Net: "tcp"} - case protUdp: + case protUDP: return &dns.Client{Net: "udp", UDPSize: uint16(bufsize)} } return nil @@ -118,8 +118,8 @@ func NewDNSServer(config DNSServerConfig, zone Zone, iface *net.Interface) (s *D if config.Timeout > 0 { s.timeout = config.Timeout } - if config.UdpBufLen > 0 { - s.udpBuf = config.UdpBufLen + if config.UDPBufLen > 0 { + s.udpBuf = config.UDPBufLen } s.mdnsCli, err = NewMDNSClient() if err != nil { @@ -152,8 +152,8 @@ func NewDNSServer(config DNSServerConfig, zone Zone, iface *net.Interface) (s *D return m } - s.udpSrv = &dns.Server{Addr: s.ListenAddr, Net: "udp", Handler: mux(protUdp)} - s.tcpSrv = &dns.Server{Addr: s.ListenAddr, Net: "tcp", Handler: mux(protTcp)} + s.udpSrv = &dns.Server{Addr: s.ListenAddr, Net: "udp", Handler: mux(protUDP)} + s.tcpSrv = &dns.Server{Addr: s.ListenAddr, Net: "tcp", Handler: mux(protTCP)} return } diff --git a/nameserver/server_test.go b/nameserver/server_test.go index d55f891c..5abc4244 100644 --- a/nameserver/server_test.go +++ b/nameserver/server_test.go @@ -15,7 +15,7 @@ const ( testRDNSsuccess = "1.2.2.10.in-addr.arpa." testRDNSfail = "4.3.2.1.in-addr.arpa." testRDNSnonlocal = "8.8.8.8.in-addr.arpa." - testUdpBufSize = 16384 + testUDPBufSize = 16384 ) var ( @@ -130,7 +130,7 @@ func TestTCPDNSServer(t *testing.T) { // handler for the fallback server: it will just return a very long response fallbackUDPHandler := func(w dns.ResponseWriter, req *dns.Msg) { - maxLen := getMaxReplyLen(req, protUdp) + maxLen := getMaxReplyLen(req, protUDP) t.Logf("Fallback UDP server got asked: returning %d answers", numAnswers) q := req.Question[0] @@ -152,16 +152,16 @@ func TestTCPDNSServer(t *testing.T) { } t.Logf("Running a DNS fallback server with UDP") - us, fallbackUdpAddr, err := runLocalUDPServer(t, "127.0.0.1:0", fallbackUDPHandler) + us, fallbackUDPAddr, err := runLocalUDPServer(t, "127.0.0.1:0", fallbackUDPHandler) wt.AssertNoErr(t, err) defer us.Shutdown() - _, fallbackPort, err := net.SplitHostPort(fallbackUdpAddr) + _, fallbackPort, err := net.SplitHostPort(fallbackUDPAddr) wt.AssertNoErr(t, err) t.Logf("Starting another fallback server, with TCP, on the same port as the UDP server") - fallbackTcpAddr := fmt.Sprintf("127.0.0.1:%s", fallbackPort) - ts, fallbackTcpAddr, err := runLocalTCPServer(t, fallbackTcpAddr, fallbackTCPHandler) + fallbackTCPAddr := fmt.Sprintf("127.0.0.1:%s", fallbackPort) + ts, fallbackTCPAddr, err := runLocalTCPServer(t, fallbackTCPAddr, fallbackTCPHandler) wt.AssertNoErr(t, err) defer ts.Shutdown() @@ -175,7 +175,7 @@ func TestTCPDNSServer(t *testing.T) { t.Logf("Creating a UDP and a TCP client") uc := new(dns.Client) - uc.UDPSize = minUdpSize + uc.UDPSize = minUDPSize tc := new(dns.Client) tc.Net = "tcp" @@ -184,8 +184,8 @@ func TestTCPDNSServer(t *testing.T) { m.RecursionDesired = true m.SetQuestion(nonLocalName, dns.TypeA) - t.Logf("Checking the fallback server at %s returns a truncated response with UDP", fallbackUdpAddr) - r, _, err := uc.Exchange(m, fallbackUdpAddr) + t.Logf("Checking the fallback server at %s returns a truncated response with UDP", fallbackUDPAddr) + r, _, err := uc.Exchange(m, fallbackUDPAddr) t.Logf("Got response from fallback server (UDP) with %d answers", len(r.Answer)) t.Logf("Response:\n%+v\n", r) wt.AssertNoErr(t, err) @@ -211,7 +211,7 @@ func TestTCPDNSServer(t *testing.T) { wt.AssertEqualInt(t, len(r.Answer), numAnswers, "number of answers (TCP)") t.Logf("Checking the WeaveDNS server at %s does not return a truncated reponse with UDP with a bigger buffer", dnsAddr) - m.SetEdns0(testUdpBufSize, false) + m.SetEdns0(testUDPBufSize, false) r, _, err = uc.Exchange(m, dnsAddr) t.Logf("UDP-large Response:\n%+v\n", r) wt.AssertNoErr(t, err) @@ -227,11 +227,11 @@ func TestTCPDNSServer(t *testing.T) { // perform a DNS query and assert the reply code, number or answers, etc func assertExchange(t *testing.T, z string, ty uint16, minAnswers int, maxAnswers int, expErr int) *dns.Msg { c := new(dns.Client) - c.UDPSize = testUdpBufSize + c.UDPSize = testUDPBufSize m := new(dns.Msg) m.RecursionDesired = true m.SetQuestion(z, ty) - m.SetEdns0(testUdpBufSize, false) // we don't want to play with truncation here... + m.SetEdns0(testUDPBufSize, false) // we don't want to play with truncation here... r, _, err := c.Exchange(m, fmt.Sprintf("127.0.0.1:%d", testPort)) t.Logf("Response:\n%+v\n", r) @@ -272,12 +272,12 @@ func runLocalUDPServer(t *testing.T, laddr string, handler dns.HandlerFunc) (*dn // run a TCP fallback server func runLocalTCPServer(t *testing.T, laddr string, handler dns.HandlerFunc) (*dns.Server, string, error) { t.Logf("Starting fallback TCP server at %s", laddr) - laddrTcp, err := net.ResolveTCPAddr("tcp", laddr) + laddrTCP, err := net.ResolveTCPAddr("tcp", laddr) if err != nil { return nil, "", err } - l, err := net.ListenTCP("tcp", laddrTcp) + l, err := net.ListenTCP("tcp", laddrTCP) if err != nil { return nil, "", err } diff --git a/nameserver/zone.go b/nameserver/zone.go index 49f27a5b..541b4174 100644 --- a/nameserver/zone.go +++ b/nameserver/zone.go @@ -97,20 +97,17 @@ func (zone *ZoneDb) LookupInaddr(inaddr string) (string, error) { } } return "", LookupError(inaddr) - } else { - Warning.Printf("[zonedb] Asked to reverse lookup %s", inaddr) - return "", LookupError(inaddr) } + Warning.Printf("[zonedb] Asked to reverse lookup %s", inaddr) + return "", LookupError(inaddr) } func (zone *ZoneDb) AddRecord(ident string, name string, ip net.IP) error { zone.mx.Lock() defer zone.mx.Unlock() fqdn := dns.Fqdn(name) - if index := zone.indexOf( - func(r Record) bool { - return r.Name == fqdn && r.IP.Equal(ip) && r.Ident == ident - }); index != -1 { + pred := func(r Record) bool { return r.Name == fqdn && r.IP.Equal(ip) && r.Ident == ident } + if index := zone.indexOf(pred); index != -1 { return DuplicateError{} } zone.recs = append(zone.recs, Record{ident, fqdn, ip}) @@ -120,15 +117,12 @@ func (zone *ZoneDb) AddRecord(ident string, name string, ip net.IP) error { func (zone *ZoneDb) DeleteRecord(ident string, ip net.IP) error { zone.mx.Lock() defer zone.mx.Unlock() - if index := zone.indexOf( - func(r Record) bool { - return r.Ident == ident && r.IP.Equal(ip) - }); index == -1 { - return LookupError(ident) - } else { + pred := func(r Record) bool { return r.Ident == ident && r.IP.Equal(ip) } + if index := zone.indexOf(pred); index != -1 { zone.recs = append(zone.recs[:index], zone.recs[index+1:]...) + return nil } - return nil + return LookupError(ident) } func (zone *ZoneDb) DeleteRecordsFor(ident string) error { diff --git a/weavedns/main.go b/weavedns/main.go index 5a8ac3ef..64642957 100644 --- a/weavedns/main.go +++ b/weavedns/main.go @@ -83,7 +83,7 @@ func main() { CacheLen: cacheLen, LocalDomain: localDomain, Timeout: timeout, - UdpBufLen: udpbuf, + UDPBufLen: udpbuf, } if len(fallback) > 0 { @@ -103,7 +103,7 @@ func main() { Debug.Printf("Starting the signals handler") go handleSignals(srv) - go weavedns.ListenHttp(version, srv, localDomain, zone, httpPort) + go weavedns.ListenHTTP(version, srv, localDomain, zone, httpPort) err = srv.Start() if err != nil { Error.Fatal("Failed to start the WeaveDNS server", err)