Skip to content

Commit 5066bfb

Browse files
committed
fix: Update Go to 1.24 and switch to golangci-lint v2
1 parent 286a156 commit 5066bfb

File tree

14 files changed

+394
-588
lines changed

14 files changed

+394
-588
lines changed

.github/workflows/lint.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ jobs:
1616
name: Lint
1717
strategy:
1818
matrix:
19-
go: [ '1.20' ]
19+
go: [ '1.24' ]
2020
fail-fast: true
2121
runs-on: ubuntu-latest
2222
steps:
23-
- name: Checkout Code
24-
uses: actions/checkout@v3
23+
- name: Checkout code
24+
uses: actions/checkout@v4
2525

26-
- name: Setup Go ${{ matrix.go }}
27-
uses: actions/setup-go@v4
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
2828
with:
2929
go-version: ${{ matrix.go }}
30-
cache: false
30+
cache: true
3131

32-
- name: Run GolangCI-Lint
33-
uses: golangci/golangci-lint-action@v6
32+
- name: Run golangci-lint
33+
uses: golangci/golangci-lint-action@v7
3434
with:
35-
version: v1.62.2
35+
version: v2.5.0
3636
args: --timeout=5m

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ jobs:
1616
name: Test
1717
strategy:
1818
matrix:
19-
go: [ '1.20' ]
19+
go: [ '1.24' ]
2020
os: [ ubuntu-latest ]
2121
fail-fast: true
2222
runs-on: ${{ matrix.os }}
2323

2424
steps:
2525
- name: Checkout code
26-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2727

2828
- name: Setup Go ${{ matrix.go }}
29-
uses: actions/setup-go@v4
29+
uses: actions/setup-go@v5
3030
with:
3131
go-version: ${{ matrix.go }}
3232
cache: false

.golangci.yml

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,91 @@
1-
linters-settings:
2-
gocyclo:
3-
min-complexity: 15
4-
dupl:
5-
threshold: 100
6-
goconst:
7-
min-len: 2
8-
min-occurrences: 2
9-
misspell:
10-
locale: US
11-
lll:
12-
line-length: 140
13-
gocritic:
14-
enabled-tags:
15-
- diagnostic
16-
- performance
17-
- style
18-
- experimental
19-
disabled-checks:
20-
- whyNoLint
21-
- unnecessaryDefer
22-
- paramTypeCombine
23-
settings:
24-
hugeParam:
25-
sizeThreshold: 256
26-
rangeValCopy:
27-
sizeThreshold: 256
28-
funlen:
29-
lines: 100
30-
statements: 50
31-
revive:
32-
rules:
33-
- name: "unused-parameter"
34-
disabled: true
1+
version: "2"
2+
3+
formatters:
4+
enable:
5+
- goimports
6+
settings:
7+
goimports:
8+
local-prefixes:
9+
- github.com/acronis/go-dbkit/
3510

3611
linters:
37-
disable-all: true
12+
settings:
13+
revive:
14+
rules:
15+
- name: exported
16+
disabled: true
17+
- name: package-comments
18+
disabled: true
19+
gocyclo:
20+
min-complexity: 15
21+
goconst:
22+
min-len: 2
23+
min-occurrences: 2
24+
govet:
25+
settings:
26+
printf:
27+
funcs:
28+
- (github.com/acronis/go-appkit/log.FieldLogger).Infof
29+
- (github.com/acronis/go-appkit/log.FieldLogger).Warnf
30+
- (github.com/acronis/go-appkit/log.FieldLogger).Errorf
31+
- (github.com/acronis/go-appkit/log.FieldLogger).Debugf
32+
misspell:
33+
locale: US
34+
lll:
35+
line-length: 140
36+
gocritic:
37+
enabled-tags:
38+
- diagnostic
39+
- performance
40+
- style
41+
- experimental
42+
disabled-checks:
43+
- paramTypeCombine
44+
- rangeValCopy
45+
settings:
46+
hugeParam:
47+
sizeThreshold: 256
48+
funlen:
49+
lines: 100
50+
statements: 50
51+
3852
enable:
3953
- bodyclose
4054
- dogsled
4155
- dupl
4256
- errcheck
43-
- exportloopref
4457
- funlen
45-
- gochecknoinits
4658
- goconst
4759
- gocritic
4860
- gocyclo
49-
- gofmt
5061
- gosec
51-
- gosimple
5262
- govet
5363
- ineffassign
5464
- lll
5565
- misspell
5666
- nakedret
5767
- revive
5868
- staticcheck
59-
- stylecheck
60-
- typecheck
6169
- unconvert
6270
- unparam
6371
- unused
6472
- whitespace
6573

66-
issues:
67-
# Don't use default excluding to be sure all exported things (method, functions, consts and so on) have comments.
68-
exclude-use-default: false
69-
exclude-rules:
70-
- path: _test\.go
71-
linters:
72-
- dogsled
73-
- dupl
74-
- errcheck
75-
- funlen
76-
- goconst
77-
- gocritic
78-
- gocyclo
79-
- gosec
80-
- govet
81-
- lll
82-
- ineffassign
83-
- noctx
84-
- unused
74+
exclusions:
75+
rules:
76+
- path: '(.+)_test\.go'
77+
linters:
78+
- dogsled
79+
- dupl
80+
- errcheck
81+
- funlen
82+
- goconst
83+
- gocritic
84+
- gocyclo
85+
- gosec
86+
- govet
87+
- lll
88+
- ineffassign
89+
- noctx
90+
- unparam
91+
- unused

config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
cfgKeyMySQLPort = "mysql.port"
3030
cfgKeyMySQLDatabase = "mysql.database"
3131
cfgKeyMySQLUser = "mysql.user"
32-
cfgKeyMySQLPassword = "mysql.password" //nolint: gosec
32+
cfgKeyMySQLPassword = "mysql.password" //nolint:gosec // Not a hardcoded password, just a config key
3333
cfgKeyMySQLTxLevel = "mysql.txLevel"
3434

3535
cfgKeySQLitePath = "sqlite3.path"
@@ -38,7 +38,7 @@ const (
3838
cfgKeyPostgresPort = "postgres.port"
3939
cfgKeyPostgresDatabase = "postgres.database"
4040
cfgKeyPostgresUser = "postgres.user"
41-
cfgKeyPostgresPassword = "postgres.password" //nolint: gosec
41+
cfgKeyPostgresPassword = "postgres.password" //nolint:gosec // Not a hardcoded password, just a config key
4242
cfgKeyPostgresTxLevel = "postgres.txLevel"
4343
cfgKeyPostgresSSLMode = "postgres.sslMode"
4444
cfgKeyPostgresSearchPath = "postgres.searchPath"
@@ -47,7 +47,7 @@ const (
4747
cfgKeyMSSQLPort = "mssql.port"
4848
cfgKeyMSSQLDatabase = "mssql.database"
4949
cfgKeyMSSQLUser = "mssql.user"
50-
cfgKeyMSSQLPassword = "mssql.password" //nolint: gosec
50+
cfgKeyMSSQLPassword = "mssql.password" //nolint:gosec // Not a hardcoded password, just a config key
5151
cfgKeyMSSQLTxLevel = "mssql.txLevel"
5252
cfgKeyMSSQLAdditionalParams = "mssql.additionalParameters"
5353
)
@@ -291,7 +291,7 @@ func (c *Config) setDialectSpecificConfig(dp config.DataProvider) error {
291291
return err
292292
}
293293

294-
// nolint: dupl
294+
//nolint:dupl // Similar config setters for different database dialects
295295
func (c *Config) setMySQLConfig(dp config.DataProvider) error {
296296
var err error
297297

@@ -317,7 +317,7 @@ func (c *Config) setMySQLConfig(dp config.DataProvider) error {
317317
return nil
318318
}
319319

320-
// nolint: dupl
320+
//nolint:dupl // Similar config setters for different database dialects
321321
func (c *Config) setMSSQLConfig(dp config.DataProvider) error {
322322
var err error
323323

@@ -350,7 +350,7 @@ func (c *Config) setMSSQLConfig(dp config.DataProvider) error {
350350
return nil
351351
}
352352

353-
// nolint: dupl
353+
//nolint:dupl // Similar config setters for different database dialects
354354
func (c *Config) setPostgresConfig(dp config.DataProvider, dialect Dialect) error {
355355
var err error
356356

config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"time"
1515

1616
"github.com/acronis/go-appkit/config"
17-
"github.com/mitchellh/mapstructure"
17+
"github.com/go-viper/mapstructure/v2"
1818
"github.com/spf13/viper"
1919
"github.com/stretchr/testify/require"
2020
"gopkg.in/yaml.v3"

dbrutil/dbrutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (s *TxSession) BeginTx(ctx context.Context) (*dbr.Tx, error) {
122122
// DoInTx begins a new transaction, calls passed function and do commit or rollback
123123
// depending on whether the function returns an error or not.
124124
func (s *TxSession) DoInTx(ctx context.Context, fn func(runner dbr.SessionRunner) error) error {
125-
if s.Connection.Dialect == dialect.SQLite3 {
125+
if s.Dialect == dialect.SQLite3 {
126126
// race of ctx cancel with transaction begin leads to 'cannot start a transaction within a transaction'
127127
// https://github.com/mattn/go-sqlite3/pull/765
128128
ctx = context.TODO()
@@ -210,9 +210,9 @@ func ParseAnnotationInQuery(query, prefix string, modifier func(string) string)
210210
}
211211
if annotation != "" {
212212
if buf.Len() != 0 {
213-
buf.WriteString("|") // nolint: gosec
213+
buf.WriteString("|") //nolint:gosec // bytes.Buffer.WriteString never returns an error
214214
}
215-
buf.WriteString(annotation) // nolint: gosec
215+
buf.WriteString(annotation) //nolint:gosec // bytes.Buffer.WriteString never returns an error
216216
}
217217
}
218218
left = right + 2

dbrutil/examples/dbr-instrumentation-1/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func main() {
4040
if err != nil {
4141
stdlog.Fatal(err)
4242
}
43-
defer conn.Close()
43+
defer func() { _ = conn.Close() }()
4444

4545
txRunner := dbrutil.NewTxRunner(conn, &sql.TxOptions{Isolation: sql.LevelReadCommitted}, nil)
4646

@@ -56,7 +56,8 @@ func main() {
5656
}
5757

5858
// The following log message will be printed:
59-
// {"level":"warn","time":"2025-02-14T16:29:55.429257+02:00","msg":"slow SQL query","pid":14030,"annotation":"query:long_operation","duration_ms":1007}
59+
// {"level":"warn","time":"2025-02-14T16:29:55.429257+02:00","msg":"slow SQL query",
60+
// "pid":14030,"annotation":"query:long_operation","duration_ms":1007}
6061

6162
// Prometheus metrics will be collected:
6263
// db_query_duration_seconds_bucket{query="query:long_operation",le="2.5"} 1

dbrutil/examples/dbr-instrumentation-2/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func main() {
3838
if err != nil {
3939
stdlog.Fatal(err)
4040
}
41-
defer conn.Close()
41+
defer func() { _ = conn.Close() }()
4242

4343
// Construct the middleware that will put the transaction runner into the request context.
4444
var txRunnerOpts dbrutil.TxRunnerMiddlewareOpts
@@ -77,7 +77,14 @@ func main() {
7777
mux := http.NewServeMux()
7878
mux.Handle("/long-operation", h)
7979
mux.Handle("/metrics", promhttp.Handler())
80-
if srvErr := http.ListenAndServe(":8080", mux); srvErr != nil && errors.Is(srvErr, http.ErrServerClosed) {
80+
srv := &http.Server{
81+
Addr: ":8080",
82+
Handler: mux,
83+
ReadTimeout: 5 * time.Second,
84+
WriteTimeout: 10 * time.Second,
85+
IdleTimeout: 120 * time.Second,
86+
}
87+
if srvErr := srv.ListenAndServe(); srvErr != nil && errors.Is(srvErr, http.ErrServerClosed) {
8188
stdlog.Fatalf("failed to start server: %v", srvErr)
8289
}
8390
}

distrlock/db_lock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ type SQLExecutor interface {
381381

382382
const createTableMigrationID = "distrlock_00001_create_table"
383383

384-
//nolint:lll
384+
//nolint:lll // SQL queries are more readable on single lines
385385
const (
386386
postgresCreateTableQuery = `CREATE TABLE IF NOT EXISTS "%s" (lock_key varchar(40) PRIMARY KEY, token uuid, expire_at timestamp);`
387387
postgresDropTableQuery = `DROP TABLE IF EXISTS "%s";`
@@ -395,7 +395,7 @@ func postgresMakeInterval(interval time.Duration) string {
395395
return strconv.FormatInt(interval.Microseconds(), 10) + " microseconds"
396396
}
397397

398-
//nolint:lll
398+
//nolint:lll // SQL queries are more readable on single lines
399399
const (
400400
mySQLCreateTableQuery = "CREATE TABLE IF NOT EXISTS `%s` (lock_key VARCHAR(40) PRIMARY KEY, token VARCHAR(36), expire_at BIGINT);"
401401
mySQLDropTableQuery = "DROP TABLE IF EXISTS `%s`;"

distrlock/db_lock_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ func assertRollbackWithCtxTimeoutError(t *gotesting.T, dialect dbkit.Dialect, tx
593593
case dbkit.DialectMySQL:
594594
ok = assert.True(t, errors.Is(rollbackErr, sql.ErrTxDone) ||
595595
errors.Is(rollbackErr, mysql.ErrInvalidConn) ||
596+
errors.Is(rollbackErr, context.DeadlineExceeded) ||
596597
rollbackErr == nil, // Rollback sometimes can return nil error in case of mysql driver .
597598
)
598599
case dbkit.DialectPostgres:

0 commit comments

Comments
 (0)