Skip to content

Commit

Permalink
add golangci-lint linter (coredns#5499)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Benkovský authored Jul 10, 2022
1 parent abc5ac8 commit c2dbb71
Show file tree
Hide file tree
Showing 104 changed files with 83 additions and 184 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: golangci-lint
on:
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.18'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
run:
timeout: 5m
linters:
disable-all: true
enable:
- deadcode
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- varcheck
- whitespace
1 change: 0 additions & 1 deletion core/dnsserver/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func newOverlapZone() *zoneOverlap {
// registerAndCheck adds a new zoneAddr for validation, it returns information about existing or overlapping with already registered
// we consider that an unbound address is overlapping all bound addresses for same zone, same port
func (zo *zoneOverlap) registerAndCheck(z zoneAddr) (existingZone *zoneAddr, overlappingZone *zoneAddr) {

if exist, ok := zo.registeredAddr[z]; ok {
// exact same zone already registered
return &exist, nil
Expand Down
4 changes: 0 additions & 4 deletions core/dnsserver/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestSplitProtocolHostPort(t *testing.T) {
if port != test.port {
t.Errorf("Test %d: (address = %s) expected port with value %s but got %s", i, test.input, test.port, port)
}

}
}

Expand Down Expand Up @@ -92,7 +91,6 @@ func TestOverlapAddressChecker(t *testing.T) {
},
},
} {

checker := newOverlapZone()
for _, call := range test.sequence {
same, overlap := checker.registerAndCheck(call.zone)
Expand All @@ -108,10 +106,8 @@ func TestOverlapAddressChecker(t *testing.T) {
if overlap.String() != call.overlapKey {
t.Errorf("Test %d: error, for zone %s, 'overlap Key' (%v) has not the expected value (%v)", i, sZone, overlap.String(), call.overlapKey)
}

}
}

}
}
}
1 change: 0 additions & 1 deletion core/dnsserver/onstartup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

func TestRegex1035PrefSyntax(t *testing.T) {

testCases := []struct {
zone string
expected bool
Expand Down
4 changes: 0 additions & 4 deletions core/dnsserver/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy

// MakeServers uses the newly-created siteConfigs to create and return a list of server instances.
func (h *dnsContext) MakeServers() ([]caddy.Server, error) {

// Now that all Keys and Directives are parsed and initialized
// lets verify that there is no overlap on the zones and addresses to listen for
errValid := h.validateZonesAndListeningAddresses()
Expand Down Expand Up @@ -197,7 +196,6 @@ func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
}
servers = append(servers, s)
}

}

return servers, nil
Expand Down Expand Up @@ -262,11 +260,9 @@ func (h *dnsContext) validateZonesAndListeningAddresses() error {
if overlapZone != nil {
return fmt.Errorf("cannot serve %s - zone overlap listener capacity with %v", akey.String(), overlapZone.String())
}

}
}
return nil

}

// groupSiteConfigsByListenAddr groups site configs by their listen
Expand Down
1 change: 0 additions & 1 deletion core/dnsserver/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func TestGroupingServers(t *testing.T) {
for _, v := range test.expectedGroups {
if _, ok := groups[v]; !ok {
t.Errorf("Test %d : expected value %v to be in the group, was not", i, v)

}
}
}
Expand Down
2 changes: 0 additions & 2 deletions core/dnsserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Server struct {
// NewServer returns a new CoreDNS server and compiles all plugins in to it. By default CH class
// queries are blocked unless queries from enableChaos are loaded.
func NewServer(addr string, group []*Config) (*Server, error) {

s := &Server{
Addr: addr,
zones: make(map[string]*Config),
Expand Down Expand Up @@ -174,7 +173,6 @@ func (s *Server) ListenPacket() (net.PacketConn, error) {
// immediately.
// This implements Caddy.Stopper interface.
func (s *Server) Stop() (err error) {

if runtime.GOOS != "windows" {
// force connections to close after timeout
done := make(chan struct{})
Expand Down
1 change: 0 additions & 1 deletion core/dnsserver/server_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (s *ServergRPC) ServePacket(p net.PacketConn) error { return nil }

// Listen implements caddy.TCPServer interface.
func (s *ServergRPC) Listen() (net.Listener, error) {

l, err := reuseport.Listen("tcp", s.Addr[len(transport.GRPC+"://"):])
if err != nil {
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions core/dnsserver/server_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (s *ServerHTTPS) ServePacket(p net.PacketConn) error { return nil }

// Listen implements caddy.TCPServer interface.
func (s *ServerHTTPS) Listen() (net.Listener, error) {

l, err := reuseport.Listen("tcp", s.Addr[len(transport.HTTPS+"://"):])
if err != nil {
return nil, err
Expand Down Expand Up @@ -141,7 +140,6 @@ func (s *ServerHTTPS) Stop() error {
// ServeHTTP is the handler that gets the HTTP request and converts to the dns format, calls the plugin
// chain, converts it back and write it to the client.
func (s *ServerHTTPS) ServeHTTP(w http.ResponseWriter, r *http.Request) {

if !s.validRequest(r) {
http.Error(w, "", http.StatusNotFound)
s.countResponse(http.StatusNotFound)
Expand Down
1 change: 0 additions & 1 deletion plugin/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ RulesCheckLoop:
return dns.RcodeSuccess, nil
}
}

}

RequestAllowCount.WithLabelValues(metrics.WithServer(ctx)).Inc()
Expand Down
1 change: 0 additions & 1 deletion plugin/auto/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

// Walk will recursively walk of the file under l.directory and adds the one that match l.re.
func (a Auto) Walk() error {

// TODO(miek): should add something so that we don't stomp on each other.

toDelete := make(map[string]bool)
Expand Down
1 change: 0 additions & 1 deletion plugin/autopath/autopath.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
w.WriteMsg(msg)
autoPathCount.WithLabelValues(metrics.WithServer(ctx)).Add(1)
return rcode, err

}
if plugin.ClientWrite(firstRcode) {
w.WriteMsg(firstReply)
Expand Down
2 changes: 0 additions & 2 deletions plugin/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (h *Azure) updateZones(ctx context.Context) error {
return fmt.Errorf("errors updating zones: %v", errs)
}
return nil

}

func updateZoneFromPublicResourceSet(recordSet publicdns.RecordSetListResultPage, newZ *file.Zone) {
Expand Down Expand Up @@ -297,7 +296,6 @@ func updateZoneFromPrivateResourceSet(recordSet privatedns.RecordSetListResultPa
Target: dns.Fqdn(*CNAME)}
newZ.Insert(cname)
}

}
}

Expand Down
4 changes: 4 additions & 0 deletions plugin/azure/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@ func setup(c *caddy.Controller) error {

publicDNSClient := publicAzureDNS.NewRecordSetsClient(env.Values[auth.SubscriptionID])
if publicDNSClient.Authorizer, err = env.GetAuthorizer(); err != nil {
cancel()
return plugin.Error("azure", err)
}

privateDNSClient := privateAzureDNS.NewRecordSetsClient(env.Values[auth.SubscriptionID])
if privateDNSClient.Authorizer, err = env.GetAuthorizer(); err != nil {
cancel()
return plugin.Error("azure", err)
}

h, err := New(ctx, publicDNSClient, privateDNSClient, keys, accessMap)
if err != nil {
cancel()
return plugin.Error("azure", err)
}
h.Fall = fall
if err := h.Run(ctx); err != nil {
cancel()
return plugin.Error("azure", err)
}

Expand Down
6 changes: 0 additions & 6 deletions plugin/backend_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request
dup := make(map[string]struct{})

for _, serv := range services {

what, ip := serv.HostType()

switch what {
Expand Down Expand Up @@ -97,7 +96,6 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ
dup := make(map[string]struct{})

for _, serv := range services {

what, ip := serv.HostType()

switch what {
Expand Down Expand Up @@ -344,7 +342,6 @@ func CNAME(ctx context.Context, b ServiceBackend, zone string, state request.Req

// TXT returns TXT records from Backend or an error.
func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, truncated bool, err error) {

services, err := b.Services(ctx, state, false, opt)
if err != nil {
return nil, false, err
Expand All @@ -353,7 +350,6 @@ func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Reque
dup := make(map[string]struct{})

for _, serv := range services {

what, _ := serv.HostType()

switch what {
Expand Down Expand Up @@ -405,7 +401,6 @@ func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Reque
dup[serv.Text] = struct{}{}
records = append(records, serv.NewTXT(state.QName()))
}

}
}

Expand Down Expand Up @@ -507,7 +502,6 @@ func BackendError(ctx context.Context, b ServiceBackend, zone string, rcode int,
}

func newAddress(s msg.Service, name string, ip net.IP, what uint16) dns.RR {

hdr := dns.RR_Header{Name: name, Rrtype: what, Class: dns.ClassINET, Ttl: s.TTL}

if what == dns.TypeA {
Expand Down
1 change: 0 additions & 1 deletion plugin/bind/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func setup(c *caddy.Controller) error {

config := dnsserver.GetConfig(c)
// addresses will be consolidated over all BIND directives available in that BlocServer
all := []string{}
Expand Down
2 changes: 1 addition & 1 deletion plugin/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func TestCacheWildcardMetadata(t *testing.T) {
ctx = metadata.ContextWithMetadata(context.TODO())
w = dnstest.NewRecorder(&test.ResponseWriter{})

c.ServeDNS(ctx, &test.ResponseWriter{}, req)
c.ServeDNS(ctx, w, req)
f := metadata.ValueFunc(ctx, "zone/wildcard")
if f == nil {
t.Fatal("expected metadata func for wildcard response retrieved from cache, got nil")
Expand Down
2 changes: 1 addition & 1 deletion plugin/chaos/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func parse(c *caddy.Controller) (string, []string, error) {
chaosVersion = caddy.AppName + "-" + caddy.AppVersion
version := ""

for c.Next() {
if c.Next() {
args := c.RemainingArgs()
if len(args) == 0 {
return trim(chaosVersion), Owners, nil
Expand Down
1 change: 0 additions & 1 deletion plugin/clouddns/clouddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func (h *CloudDNS) updateZones(ctx context.Context) error {
(*z[i]).z = newZ
h.zMu.Unlock()
}

}(zName, z)
}
// Collect errors (if any). This will also sync on all zones updates
Expand Down
1 change: 0 additions & 1 deletion plugin/clouddns/clouddns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func TestCloudDNS(t *testing.T) {

m.Authoritative = true
rcode = dns.RcodeSuccess

}

m.SetRcode(r, rcode)
Expand Down
3 changes: 3 additions & 0 deletions plugin/clouddns/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ func setup(c *caddy.Controller) error {
ctx, cancel := context.WithCancel(context.Background())
client, err := f(ctx, opt)
if err != nil {
cancel()
return err
}

h, err := New(ctx, client, keys, up)
if err != nil {
cancel()
return plugin.Error("clouddns", c.Errf("failed to create plugin: %v", err))
}
h.Fall = fall

if err := h.Run(ctx); err != nil {
cancel()
return plugin.Error("clouddns", c.Errf("failed to initialize plugin: %v", err))
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/debug/pcap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNoDebug(t *testing.T) {
}
}

func ExampleLogHexdump() {
func ExampleHexdump() {
buf, _ := msg().Pack()
h := hexdump(buf)
fmt.Println(string(h))
Expand Down
Loading

0 comments on commit c2dbb71

Please sign in to comment.