Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
git diff --exit-code -- go.mod go.sum
- name: Check installation in CoreDNS
run: make integration
- name: Benchmark plugin
run: make benchmark

dependency-review:
if: github.event_name == 'pull_request'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ coredns.exe
coredns.exe~
Corefile
/build/
!/examples/Corefile
/examples/example.org.db*
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.26.2
1.27.0
136 changes: 136 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
version: "2"

run:
timeout: 5m
build-tags: [integration, grpcnotrace]
tests: true

linters:
default: all
disable:
- exhaustruct # Superseded by exhaustruct_v5.
- wsl # Superseded by wsl_v5.
- gomodguard # Superseded by gomodguard_v2.
- depguard # No import allowlist is defined for this plugin.
- goheader # CoreDNS does not require a license header in each Go file.
- noinlineerr # Keep standard Go scoped error checks.
- testpackage # Unit tests exercise private plugin configuration and handlers.
settings:
cyclop:
max-complexity: 10
package-average: 5
decorder:
dec-order: [const, type, var, func]
disable-dec-order-check: false
disable-init-func-first-check: false
disable-dec-num-check: false
disable-type-dec-num-check: false
disable-const-dec-num-check: false
disable-var-dec-num-check: false
errcheck:
exclude-functions:
- '(net.Conn).Close' # Socket cleanup cannot change a completed or cancelled transfer.
exhaustruct_v5:
explicit-mode: true
enforce-patterns: ['^github\.com/coredns/dynapi/.*']
allow-empty: true
allow-empty-returns: true
allow-empty-declarations: true
funcorder:
constructor: true
struct-method: true
function: true
funlen:
lines: 60
statements: 40
ignore-comments: false
gocognit:
min-complexity: 15
gocritic:
enabled-tags: [diagnostic, style, performance, experimental, opinionated]
disabled-checks: [unnamedResult] # nonamedreturns owns return-value style.
gocyclo:
min-complexity: 10
govet:
enable-all: true
ireturn:
allow:
- anon
- error
- empty
- stdlib
- generic
- '^github\.com/miekg/dns\.RR$'
- '^github\.com/coredns/coredns/plugin\.Handler$'
lll:
line-length: 120
maintidx:
under: 30
nestif:
min-complexity: 4
nolintlint:
require-explanation: true
require-specific: true
prealloc:
for-loops: true
revive:
enable-all-rules: true
directives:
- name: specify-disable-reason
rules:
- name: receiver-naming
- name: cognitive-complexity
arguments: [15]
- name: line-length-limit
arguments: [120]
- name: multiline-if-init
disabled: true # golines wraps calls in standard Go if statements.
- name: empty-lines
disabled: true # wsl_v5 owns blank line placement.
- name: function-length
disabled: true # funlen owns function length limits.
- name: add-constant
disabled: true # mnd checks numeric literals without flagging protocol strings.
wrapcheck:
ignore-sig-regexps:
- 'caddyfile.Dispenser.*(ArgErr|Err)'
- 'plugin.(Error|NextOrFailure)'
staticcheck:
checks: [all]
varnamelen:
ignore-names: [err, ok, ctx, id, ip, rr, r, w, t]
whitespace:
multi-if: true
multi-func: false # gofumpt removes blank lines at the start of functions.
wsl_v5:
default: all
disable: [leading-whitespace] # whitespace requires space after multiline conditions.
exclusions:
presets: []
rules:
- path: '(^main\.go$|plugins/dynapi/setup\.go$)'
linters: [gochecknoinits]
text: 'init'
- path: 'plugins/dynapi/setup\.go$'
linters: [gochecknoglobals]
text: 'log'
- path: '_test\.go$'
linters: [exhaustruct_v5, goconst, mnd]
text: '.*' # Test fixtures intentionally use literal values and partial states.
- path: 'plugins/dynapi/config_test\.go$'
linters: [gosec]
text: 'G101' # Public test credentials are not real secrets.

formatters:
enable: [gci, gofumpt, golines]
settings:
gci:
sections: [standard, default, localmodule]
gofumpt:
module-path: github.com/coredns/dynapi
golines:
max-len: 100

issues:
max-issues-per-linter: 0
max-same-issues: 0
29 changes: 23 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ BINARY ?= coredns
GITCOMMIT ?= development
GO ?= go
BUILDOPTS ?= -tags=grpcnotrace
GOLANGCI_LINT_VERSION := v2.14.0
GOLANGCI_LINT ?= $(GO) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: all coredns build format format-check test vet verify integration
.PHONY: all coredns build format format-check test vet lint verify integration openapi openapi-check benchmark

all: coredns

Expand All @@ -15,21 +17,36 @@ coredns:
build: coredns

format:
gofmt -w .
$(GOLANGCI_LINT) fmt

format-check:
@test -z "$$(gofmt -l .)" || { gofmt -l .; exit 1; }
$(GOLANGCI_LINT) fmt --diff

test:
$(GO) test -race $(BUILDOPTS) ./...

vet:
$(GO) vet $(BUILDOPTS) ./...

verify: format-check
lint:
$(GOLANGCI_LINT) config verify
$(GOLANGCI_LINT) run

verify: format-check lint openapi-check
$(GO) build $(BUILDOPTS) ./...
$(GO) vet $(BUILDOPTS) ./...
$(GO) test -race $(BUILDOPTS) ./...

integration: coredns
COREDNS_DYNAPI_BINARY="$(abspath $(BINARY))" $(GO) test -race -tags=integration,grpcnotrace -run '^TestInstallation$$' -count=1 .
integration:
$(GO) build -race $(BUILDOPTS) -o $(BINARY) .
COREDNS_DYNAPI_BINARY="$(abspath $(BINARY))" $(GO) test -race -tags=integration,grpcnotrace -run '^Test(Installation|HTTPAPI)$$' -count=1 .

openapi:
@$(GO) run $(BUILDOPTS) ./cmd/openapi > openapi.yaml.tmp && mv openapi.yaml.tmp openapi.yaml

openapi-check:
@set -eu; document=$$(mktemp); trap 'rm -f "$$document"' EXIT; \
$(GO) run $(BUILDOPTS) ./cmd/openapi > "$$document"; diff -u openapi.yaml "$$document"

benchmark:
$(GO) test $(BUILDOPTS) -run '^$$' -bench . -benchmem ./plugins/dynapi
Loading
Loading