Skip to content

Commit 4a92940

Browse files
authored
Fix: update Go version and upgrade dependencies across modules (#285)
1 parent ec8403e commit 4a92940

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+698
-466
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ jobs:
1414
steps:
1515
- uses: actions/setup-go@v5
1616
with:
17-
go-version: '1.24'
17+
go-version: '1.25'
1818
cache: false
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v5
2020
- name: install deps
2121
run: |
2222
go get -u golang.org/x/tools/cmd/goimports
2323
go install golang.org/x/tools/cmd/goimports
2424
2525
- name: golangci-lint
26-
uses: golangci/golangci-lint-action@v6
26+
uses: golangci/golangci-lint-action@v8
27+
continue-on-error: true
2728
with:
2829
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
2930
version: latest

.golangci.yml

Lines changed: 218 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,226 @@
1-
run:
2-
timeout: 10m
3-
4-
linters-settings:
5-
lll:
6-
line-length: 170
7-
dupl:
8-
threshold: 400
9-
10-
issues:
11-
# don't skip warning about doc comments
12-
exclude-use-default: false
13-
14-
# restore some of the defaults
15-
# (fill in the rest as needed)
16-
exclude-rules:
17-
- linters: [errcheck]
18-
text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
19-
exclude-dirs:
20-
- vendor
21-
- proto
22-
- test
23-
exclude-files:
24-
- ".*\\_test\\.go$"
25-
- ".*\\_string\\.go$"
26-
- "pkg/response/actions/k8s/control.go"
27-
- "pkg/response/actions/k8s/search.go"
1+
# This configuration file is not a recommendation.
2+
#
3+
# We intentionally use a limited set of linters.
4+
# This configuration file is used with different version of golangci-lint to avoid regressions:
5+
# the linters can change between version,
6+
# their configuration may be not compatible or their reports can be different,
7+
# and this can break some of our tests.
8+
# Also, some linters are not relevant for the project (e.g. linters related to SQL).
9+
#
10+
# We have specific constraints, so we use a specific configuration.
11+
#
12+
# See the file `.golangci.reference.yml` to have a list of all available configuration options.
13+
14+
version: "2"
2815

2916
linters:
30-
disable-all: true
17+
default: none
18+
# This list of linters is not a recommendation (same thing for all this configuration file).
19+
# We intentionally use a limited set of linters.
20+
# See the comment on top of this file.
3121
enable:
32-
- misspell
33-
# - structcheck
34-
# - golint
35-
- govet
36-
# - deadcode
22+
- bodyclose
23+
- copyloopvar
24+
- depguard
25+
- dogsled
26+
- dupl
3727
- errcheck
38-
# - varcheck
28+
- errorlint
29+
- funlen
30+
- gocheckcompilerdirectives
31+
- gochecknoinits
3932
- goconst
40-
- unparam
41-
- ineffassign
42-
- nakedret
33+
- gocritic
4334
- gocyclo
35+
- godox
36+
- mnd
37+
- goprintffuncname
38+
- gosec
39+
- govet
40+
- intrange
41+
- ineffassign
4442
- lll
45-
- dupl
43+
- misspell
44+
- nakedret
45+
- noctx
46+
- nolintlint
47+
- revive
48+
- staticcheck
49+
- testifylint
50+
- unconvert
51+
- unparam
52+
- unused
53+
- whitespace
54+
55+
settings:
56+
depguard:
57+
rules:
58+
logger:
59+
deny:
60+
# logging is allowed only by logutils.Log,
61+
- pkg: "github.com/sirupsen/logrus"
62+
desc: logging is allowed only by logutils.Log.
63+
- pkg: "github.com/pkg/errors"
64+
desc: Should be replaced by standard lib errors package.
65+
- pkg: "github.com/instana/testify"
66+
desc: It's a fork of github.com/stretchr/testify.
67+
files:
68+
# logrus is allowed to use only in logutils package.
69+
- "!**/pkg/logutils/**.go"
70+
dupl:
71+
threshold: 100
72+
funlen:
73+
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
74+
statements: 50
75+
goconst:
76+
min-len: 2
77+
min-occurrences: 3
78+
gocritic:
79+
enabled-tags:
80+
- diagnostic
81+
- experimental
82+
- opinionated
83+
- performance
84+
- style
85+
disabled-checks:
86+
- dupImport # https://github.com/go-critic/go-critic/issues/845
87+
- ifElseChain
88+
- octalLiteral
89+
- whyNoLint
90+
gocyclo:
91+
min-complexity: 15
92+
godox:
93+
keywords:
94+
- FIXME
95+
mnd:
96+
# don't include the "operation" and "assign"
97+
checks:
98+
- argument
99+
- case
100+
- condition
101+
- return
102+
ignored-numbers:
103+
- '0'
104+
- '1'
105+
- '2'
106+
- '3'
107+
ignored-functions:
108+
- strings.SplitN
109+
- Init
110+
govet:
111+
settings:
112+
printf:
113+
funcs:
114+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Infof
115+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Warnf
116+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Errorf
117+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Fatalf
118+
enable:
119+
- nilness
120+
- shadow
121+
errorlint:
122+
asserts: false
123+
lll:
124+
line-length: 140
125+
misspell:
126+
locale: US
127+
ignore-rules:
128+
- "importas" # linter name
129+
nolintlint:
130+
allow-unused: false # report any unused nolint directives
131+
require-explanation: true # require an explanation for nolint directives
132+
require-specific: true # require nolint directives to be specific about which linter is being skipped
133+
revive:
134+
rules:
135+
- name: indent-error-flow
136+
- name: unexported-return
137+
disabled: true
138+
- name: unused-parameter
139+
- name: unused-receiver
140+
141+
exclusions:
142+
presets:
143+
- comments
144+
- std-error-handling
145+
- common-false-positives
146+
- legacy
147+
paths:
148+
- vendor
149+
- proto
150+
- test
151+
- ".*\\_test\\.go$"
152+
- ".*\\_string\\.go$"
153+
- "pkg/response/actions/k8s/control.go"
154+
- "pkg/response/actions/k8s/search.go"
155+
- "core/server"
156+
- pkg/response/actions/k8s
157+
rules:
158+
- path: (.+)_test\.go
159+
linters:
160+
- dupl
161+
- mnd
162+
- lll
163+
164+
# Based on existing code, the modifications should be limited to make maintenance easier.
165+
- path: pkg/golinters/unused/unused.go
166+
linters: [gocritic]
167+
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)"
168+
169+
# Related to the result of computation but divided multiple times by 1024.
170+
- path: test/bench/bench_test.go
171+
linters: [gosec]
172+
text: "G115: integer overflow conversion uint64 -> int"
173+
174+
# The files created during the tests don't need to be secured.
175+
- path: scripts/website/expand_templates/linters_test.go
176+
linters: [gosec]
177+
text: "G306: Expect WriteFile permissions to be 0600 or less"
178+
179+
# Related to migration command.
180+
- path: pkg/commands/internal/migrate/two/
181+
linters:
182+
- lll
183+
184+
# Related to migration command.
185+
- path: pkg/commands/internal/migrate/
186+
linters:
187+
- gocritic
188+
text: "hugeParam:"
189+
190+
# The codes are close but this is not duplication.
191+
- path: pkg/commands/(formatters|linters).go
192+
linters:
193+
- dupl
194+
195+
# Deprecated linters
196+
- path: pkg/lint/lintersdb/builder_linter.go
197+
text: "SA1019: wsl.NewV4 is deprecated: use NewV5 instead."
198+
linters:
199+
- staticcheck
200+
- path: pkg/golinters/wsl/wsl.go
201+
text: "SA1019: config.WSLv4Settings is deprecated: use WSLv5Settings instead."
202+
linters:
203+
- staticcheck
204+
205+
formatters:
206+
enable:
207+
- gofmt
46208
- goimports
209+
settings:
210+
gofmt:
211+
rewrite-rules:
212+
- pattern: 'interface{}'
213+
replacement: 'any'
214+
goimports:
215+
local-prefixes:
216+
- github.com/golangci/golangci-lint/v2
217+
exclusions:
218+
paths:
219+
- vendor
220+
- proto
221+
- test
222+
- ".*\\_test\\.go$"
223+
- ".*\\_string\\.go$"
224+
- "pkg/response/actions/k8s/control.go"
225+
- "pkg/response/actions/k8s/search.go"
226+
- "core/server"

.pre-commit-hooks.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
- id: golangci-lint
2+
name: golangci-lint
3+
description: Fast linters runner for Go. Note that only modified files are linted, so linters like 'unused' that need to scan all files won't work as expected.
4+
entry: golangci-lint run --new-from-rev HEAD --fix
5+
types: [go]
6+
language: golang
7+
require_serial: true
8+
pass_filenames: false
9+
- id: golangci-lint-full
10+
name: golangci-lint-full
11+
description: Fast linters runner for Go. Runs on all files in the module. Use this hook if you use pre-commit in CI.
12+
entry: golangci-lint run --fix
13+
types: [go]
14+
language: golang
15+
require_serial: true
16+
pass_filenames: false
17+
- id: golangci-lint-fmt
18+
name: golangci-lint-fmt
19+
description: Fast linters runner for Go. Formats all files in the repo.
20+
entry: golangci-lint fmt
21+
types: [go]
22+
language: golang
23+
require_serial: true
24+
pass_filenames: false
25+
- id: golangci-lint-config-verify
26+
name: golangci-lint-config-verify
27+
description: Verifies the configuration file
28+
entry: golangci-lint config verify
29+
files: '\.golangci\.(?:yml|yaml|toml|json)'
30+
language: golang
31+
pass_filenames: false

core/logger/writer/file.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ func NewFileWriter(opts ...Option) (*FileWriter, error) {
4343
p.num--
4444
filename = p.getFilenameAccordingToTimestamp()
4545
}
46-
//文件不存在
46+
// 文件不存在
4747
break
4848
}
49-
//存在,但是报错了
49+
// 存在,但是报错了
5050
return nil, err
5151
}
5252
p.num++
@@ -79,7 +79,7 @@ func (p *FileWriter) checkFile() {
7979
info, _ := p.file.Stat()
8080
if strings.Contains(p.file.Name(), time.Now().Format(fileNameTimeFormat)) ||
8181
(p.opts.cap > 0 && uint(info.Size()) > p.opts.cap) {
82-
//生成新文件
82+
// 生成新文件
8383
if uint(info.Size()) > p.opts.cap {
8484
p.num++
8585
} else {

core/logger/writer/loki.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package writer
22

3-
//import (
3+
// import (
44
// "bytes"
55
// "errors"
66
// "io"
@@ -24,7 +24,7 @@ package writer
2424
// * @Last Modified time: 2024/5/7 18:37:00
2525
// */
2626
//
27-
//type LokiWriter struct {
27+
// type LokiWriter struct {
2828
// opts Options
2929
// entries chan logproto.Entry
3030
//}

core/logger/writer/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import "time"
1212
// Options 可配置参数
1313
type Options struct {
1414
path string
15-
suffix string //文件扩展名
15+
suffix string // 文件扩展名
1616
cap uint
1717
lokiURL string
1818
lokiLabels map[string]string

0 commit comments

Comments
 (0)