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
12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
68 changes: 15 additions & 53 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,26 @@ name: Go

on:
push:
branches: [main]
pull_request:
branches:
- master
branches: [main]

jobs:
golangci-lint:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
go-version: ['1.20', '1.21', '1.22', '1.23', '1.24']
os: [ubuntu-latest, macos-latest, windows-latest]
env:
OS: ${{ matrix.os }}
GOVERSION: ${{ matrix.go-version }}
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
check-latest: true
cache: true
- name: Display Go version
run: go version
- name: Install dependencies
run: make setup
- name: Test
run: make ci
- name: Archive code coverage results
uses: actions/upload-artifact@v4
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
name: code-coverage-report-${{ matrix.os }}-${{ matrix.go-version }}
path: coverage.txt
go-version: 1.22

coverage:
needs: tests
runs-on: ubuntu-latest
- name: Build
run: make build

steps:
- name: Download a linux coverage report
uses: actions/download-artifact@v4
with:
name: code-coverage-report-ubuntu-latest-1.24
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
flags: unittest
- name: Test
run: make test

- name: Lint
run: make lint
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ Gopkg.lock

# cover
coverage.txt

# added by lint-install
out/
231 changes: 231 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
## Golden config for golangci-lint - strict, but within the realm of what Go authors might use.
#
# This is tied to the version of golangci-lint listed in the Makefile, usage with other
# versions of golangci-lint will yield errors and/or false positives.
#
# Docs: https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml
# Based heavily on https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322

version: "2"

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

formatters:
enable:
# - gci
# - gofmt
- gofumpt
# - goimports
# - golines
- swaggo

settings:
golines:
# Default: 100
max-len: 120

linters:
default: all
disable:
# linters that give advice contrary to what the Go authors advise
- decorder # checks declaration order and count of types, constants, variables and functions
- dupword # [useless without config] checks for duplicate words in the source code
- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized
- forcetypeassert # [replaced by errcheck] finds forced type assertions
- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
- gochecknoglobals # checks that no global variables exist
- cyclop # replaced by revive
- funlen # replaced by revive
- godox # TODO's are OK
- ireturn # It's OK
- musttag
- nonamedreturns
- goconst # finds repeated strings that could be replaced by a constant
- goheader # checks is file header matches to pattern
- gomodguard # [use more powerful depguard] allow and block lists linter for direct Go module dependencies
- err113 # bad advice about dynamic errors
- lll # [replaced by golines] reports long lines
- mnd # detects magic numbers, duplicated by revive
- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
- noinlineerr # disallows inline error handling `if err := ...; err != nil {`
- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
- tagliatelle # needs configuration
- testableexamples # checks if examples are testable (have an expected output)
- testpackage # makes you use a separate _test package
- paralleltest # not every test should be in parallel
- wrapcheck # not required
- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
- wsl_v5 # [too strict and mostly code is not more readable] add or remove empty lines
- zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event

# All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml
settings:
depguard:
rules:
"deprecated":
files:
- "$all"
deny:
- pkg: github.com/golang/protobuf
desc: Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules
- pkg: github.com/satori/go.uuid
desc: Use github.com/google/uuid instead, satori's package is not maintained
- pkg: github.com/gofrs/uuid$
desc: Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5
"non-test files":
files:
- "!$test"
deny:
- pkg: math/rand$
desc: Use math/rand/v2 instead, see https://go.dev/blog/randv2
- pkg: "github.com/sirupsen/logrus"
desc: not allowed
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package

dupl:
# token count (default: 150)
threshold: 300

embeddedstructfieldcheck:
# Checks that sync.Mutex and sync.RWMutex are not used as embedded fields.
forbid-mutex: true

errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
check-type-assertions: true

exhaustive:
# Program elements to check for exhaustiveness.
# Default: [ switch ]
check:
- switch
- map
default-signifies-exhaustive: true

fatcontext:
# Check for potential fat contexts in struct pointers.
# May generate false positives.
# Default: false
check-struct-pointers: true

funcorder:
# Checks if the exported methods of a structure are placed before the non-exported ones.
struct-method: false

gocognit:
min-complexity: 55

gocritic:
enable-all: true
disabled-checks:
- paramTypeCombine
# The list of supported checkers can be found at https://go-critic.com/overview.
settings:
captLocal:
# Whether to restrict checker to params only.
paramsOnly: false
underef:
# Whether to skip (*x).method() calls where x is a pointer receiver.
skipRecvDeref: false
hugeParam:
# Default: 80
sizeThreshold: 200

govet:
enable-all: true

godot:
scope: toplevel

inamedparam:
# Skips check for interface methods with only a single parameter.
skip-single-param: true

nakedret:
# Default: 30
max-func-lines: 4

nestif:
min-complexity: 12

nolintlint:
# Exclude following linters from requiring an explanation.
# Default: []
allow-no-explanation: [funlen, gocognit, golines]
# Enable to require an explanation of nonzero length after each nolint directive.
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
require-specific: true

revive:
enable-all-rules: true
rules:
- name: add-constant
severity: warning
disabled: false
exclude: [""]
arguments:
- max-lit-count: "5"
allow-strs: '"","\n"'
allow-ints: "0,1,2,3,256,1024"
allow-floats: "0.0,0.,1.0,1.,2.0,2."
- name: cognitive-complexity
arguments: [50]
- name: cyclomatic
severity: warning
arguments: [30]
- name: function-length
arguments: [150, 225]
- name: line-length-limit
arguments: [150]
- name: nested-structs
disabled: true

rowserrcheck:
# database/sql is always checked.
# Default: []
packages:
- github.com/jmoiron/sqlx

perfsprint:
# optimize fmt.Sprintf("x: %s", y) into "x: " + y
strconcat: false

staticcheck:
checks:
- all

usetesting:
# Enable/disable `os.TempDir()` detections.
# Default: false
os-temp-dir: true

varnamelen:
max-distance: 40
min-name-length: 2

exclusions:
# Default: []
presets:
- common-false-positives
rules:
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
- text: '^shadow: declaration of "(err|ok)" shadows declaration'
linters:
- govet
- text: "parameter 'ctx' seems to be unused, consider removing or renaming it as _"
linters:
- revive
- path: _test\.go
linters:
- dupl
- gosec
- noctx
- perfsprint
- revive
- varnamelen
16 changes: 16 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
extends: default

rules:
braces:
max-spaces-inside: 1
brackets:
max-spaces-inside: 1
comments: disable
comments-indentation: disable
document-start: disable
line-length:
level: warning
max: 160
allow-non-breakable-inline-mappings: true
truthy: disable
Loading