diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0481be5..35e06d7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,7 +8,7 @@ jobs: name: Build strategy: matrix: - go-version: [1.21.x, 1.22.x] + go-version: [1.23.x, 1.24.x] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 6537d94..850823e 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -9,6 +9,6 @@ jobs: steps: - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: version: latest diff --git a/.golangci.toml b/.golangci.toml deleted file mode 100644 index 799416c..0000000 --- a/.golangci.toml +++ /dev/null @@ -1,192 +0,0 @@ -[run] -# This is needed for precious, which may run multiple instances -# in parallel -allow-parallel-runners = true -go = "1.21" -tests = true -timeout = "10m" - -[linters] -enable-all = true -disable = [ - "cyclop", - "depguard", - "err113", - "execinquery", - "exhaustive", - "exhaustruct", - "forcetypeassert", - "funlen", - "gochecknoglobals", - "godox", - "gomnd", - "inamedparam", - "interfacebloat", - "mnd", - "nlreturn", - "nonamedreturns", - "paralleltest", - "thelper", - "testpackage", - - "varnamelen", - "wrapcheck", - "wsl", - - # Require Go 1.22 - "copyloopvar", - "intrange", -] - -[linters-settings.errorlint] -errorf = true -asserts = true -comparison = true - -[linters-settings.exhaustive] -default-signifies-exhaustive = true - -[linters-settings.forbidigo] -# Forbid the following identifiers -forbid = [ - { p = "Geoip", msg = "you should use `GeoIP`" }, - { p = "geoIP", msg = "you should use `geoip`" }, - { p = "Maxmind", msg = "you should use `MaxMind`" }, - { p = "^maxMind", msg = "you should use `maxmind`" }, - { p = "Minfraud", msg = "you should use `MinFraud`" }, - { p = "^minFraud", msg = "you should use `minfraud`" }, - { p = "^math.Max$", msg = "you should use the max built-in instead." }, - { p = "^math.Min$", msg = "you should use the min built-in instead." }, - { p = "^os.IsNotExist", msg = "As per their docs, new code should use errors.Is(err, fs.ErrNotExist)." }, - { p = "^os.IsExist", msg = "As per their docs, new code should use errors.Is(err, fs.ErrExist)" }, -] - -[linters-settings.gci] -sections = ["standard", "default", "prefix(github.com/oschwald/maxminddb-golang)"] - -[linters-settings.gofumpt] -extra-rules = true - -[linters-settings.govet] -enable-all = true -disable = "shadow" - -[linters-settings.lll] -line-length = 120 -tab-width = 4 - -[linters-settings.misspell] -locale = "US" - -[[linters-settings.misspell.extra-words]] -typo = "marshall" -correction = "marshal" - -[[linters-settings.misspell.extra-words]] -typo = "marshalling" -correction = "marshaling" - -[[linters-settings.misspell.extra-words]] -typo = "marshalls" -correction = "marshals" - -[[linters-settings.misspell.extra-words]] -typo = "unmarshall" -correction = "unmarshal" - -[[linters-settings.misspell.extra-words]] -typo = "unmarshalling" -correction = "unmarshaling" - -[[linters-settings.misspell.extra-words]] -typo = "unmarshalls" -correction = "unmarshals" - -[linters-settings.nolintlint] -allow-unused = false -allow-no-explanation = ["lll", "misspell"] -require-explanation = true -require-specific = true - -[linters-settings.revive] -enable-all-rules = true -ignore-generated-header = true -severity = "warning" - -[[linters-settings.revive.rules]] -name = "add-constant" -disabled = true - -[[linters-settings.revive.rules]] -name = "cognitive-complexity" -disabled = true - -[[linters-settings.revive.rules]] -name = "confusing-naming" -disabled = true - -[[linters-settings.revive.rules]] -name = "confusing-results" -disabled = true - -[[linters-settings.revive.rules]] -name = "cyclomatic" -disabled = true - -[[linters-settings.revive.rules]] -name = "deep-exit" -disabled = true - -[[linters-settings.revive.rules]] -name = "flag-parameter" -disabled = true - -[[linters-settings.revive.rules]] -name = "function-length" -disabled = true - -[[linters-settings.revive.rules]] -name = "function-result-limit" -disabled = true - -[[linters-settings.revive.rules]] -name = "line-length-limit" -disabled = true - -[[linters-settings.revive.rules]] -name = "max-public-structs" -disabled = true - -[[linters-settings.revive.rules]] -name = "nested-structs" -disabled = true - -[[linters-settings.revive.rules]] -name = "unchecked-type-assertion" -disabled = true - -[[linters-settings.revive.rules]] -name = "unhandled-error" -disabled = true - -[linters-settings.tagliatelle.case.rules] -avro = "snake" -bson = "snake" -env = "upperSnake" -envconfig = "upperSnake" -json = "snake" -mapstructure = "snake" -xml = "snake" -yaml = "snake" - -[linters-settings.unparam] -check-exported = true - - -[[issues.exclude-rules]] -linters = [ - "govet", - "revive", -] -path = "_test.go" -text = "fieldalignment:" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4904561 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,174 @@ +version: "2" +run: + go: "1.23" + tests: true + allow-parallel-runners: true +linters: + default: all + disable: + - cyclop + - depguard + - err113 + - exhaustive + - exhaustruct + - forcetypeassert + - funlen + - gochecknoglobals + - gocognit + - godox + - gosmopolitan + - inamedparam + - interfacebloat + - mnd + - nlreturn + - nonamedreturns + - paralleltest + - testpackage + - thelper + - varnamelen + - wrapcheck + - wsl + settings: + errorlint: + errorf: true + asserts: true + comparison: true + exhaustive: + default-signifies-exhaustive: true + forbidigo: + forbid: + - pattern: Geoip + msg: you should use `GeoIP` + - pattern: geoIP + msg: you should use `geoip` + - pattern: Maxmind + msg: you should use `MaxMind` + - pattern: ^maxMind + msg: you should use `maxmind` + - pattern: Minfraud + msg: you should use `MinFraud` + - pattern: ^minFraud + msg: you should use `minfraud` + - pattern: ^math.Max$ + msg: you should use the max built-in instead. + - pattern: ^math.Min$ + msg: you should use the min built-in instead. + - pattern: ^os.IsNotExist + msg: As per their docs, new code should use errors.Is(err, fs.ErrNotExist). + - pattern: ^os.IsExist + msg: As per their docs, new code should use errors.Is(err, fs.ErrExist) + gosec: + excludes: + - G115 + govet: + disable: + - shadow + enable-all: true + lll: + line-length: 120 + tab-width: 4 + misspell: + locale: US + extra-words: + - typo: marshall + correction: marshal + - typo: marshalling + correction: marshaling + - typo: marshalls + correction: marshals + - typo: unmarshall + correction: unmarshal + - typo: unmarshalling + correction: unmarshaling + - typo: unmarshalls + correction: unmarshals + nolintlint: + require-explanation: true + require-specific: true + allow-no-explanation: + - lll + - misspell + allow-unused: false + revive: + severity: warning + enable-all-rules: true + rules: + - name: add-constant + disabled: true + - name: cognitive-complexity + disabled: true + - name: confusing-naming + disabled: true + - name: confusing-results + disabled: true + - name: cyclomatic + disabled: true + - name: deep-exit + disabled: true + - name: flag-parameter + disabled: true + - name: function-length + disabled: true + - name: function-result-limit + disabled: true + - name: line-length-limit + disabled: true + - name: max-public-structs + disabled: true + - name: nested-structs + disabled: true + - name: unchecked-type-assertion + disabled: true + - name: unhandled-error + disabled: true + tagliatelle: + case: + rules: + avro: snake + bson: snake + env: upperSnake + envconfig: upperSnake + json: snake + mapstructure: snake + xml: snake + yaml: snake + unparam: + check-exported: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - govet + - revive + path: _test.go + text: 'fieldalignment:' + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + - golines + settings: + gci: + sections: + - standard + - default + - prefix(github.com/oschwald/geoip2-golang) + gofumpt: + extra-rules: true + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/go.mod b/go.mod index 5a6c087..2562b03 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/oschwald/geoip2-golang -go 1.21 +go 1.23.0 require ( github.com/oschwald/maxminddb-golang v1.13.1 diff --git a/reader_test.go b/reader_test.go index 56e0552..c81bb12 100644 --- a/reader_test.go +++ b/reader_test.go @@ -271,7 +271,7 @@ func BenchmarkCity(b *testing.B) { var city *City ip := make(net.IP, 4) - for i := 0; i < b.N; i++ { + for range b.N { randomIPv4Address(r, ip) city, err = db.City(ip) if err != nil { @@ -297,7 +297,7 @@ func BenchmarkASN(b *testing.B) { var asn *ASN ip := make(net.IP, 4) - for i := 0; i < b.N; i++ { + for range b.N { randomIPv4Address(r, ip) asn, err = db.ASN(ip) if err != nil {