Skip to content

Commit 80419cd

Browse files
committed
feat: added .golangci.yml config file and upgraded dependencies
1 parent fb21cd7 commit 80419cd

22 files changed

+501
-183
lines changed

.golangci.yml

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
2+
# golangci-lint configuration for github.com/ralvarezdev/go-databases
3+
# Based on v2.5.0 best practices
4+
# Last updated: 2025-10-21
5+
6+
version: "2"
7+
8+
run:
9+
timeout: 5m
10+
concurrency: 0 # Auto-detect CPU cores
11+
tests: true
12+
modules-download-mode: readonly
13+
go: '1.25.1' # Match your project's Go version
14+
relative-path-mode: gomod
15+
16+
output:
17+
formats:
18+
text:
19+
path: stdout
20+
print-linter-name: true
21+
colors: true
22+
sort-order:
23+
- severity
24+
- linter
25+
- file
26+
show-stats: true
27+
28+
formatters:
29+
enable:
30+
- goimports
31+
- golines
32+
33+
settings:
34+
goimports:
35+
local-prefixes:
36+
- github.com/ralvarezdev/go-databases
37+
38+
golines:
39+
max-len: 120
40+
shorten-comments: true
41+
42+
exclusions:
43+
generated: lax
44+
paths:
45+
- "vendor/"
46+
- "third_party/"
47+
48+
linters:
49+
enable:
50+
# Essential Linters
51+
- govet
52+
- staticcheck
53+
- unused
54+
- goconst
55+
- godoclint
56+
- sloglint
57+
- misspell
58+
59+
# Security Linters
60+
- gosec
61+
- bidichk
62+
63+
# Resource Management
64+
- bodyclose
65+
- sqlclosecheck
66+
- rowserrcheck
67+
68+
# Error Handling Linters
69+
- errorlint
70+
- errcheck
71+
- nilerr
72+
- nilnil
73+
74+
# Code Quality
75+
- dupl
76+
- nestif
77+
- ineffassign
78+
- revive
79+
- gocritic
80+
- unconvert
81+
- wastedassign
82+
- usestdlibvars
83+
84+
# Context & Concurrency
85+
- contextcheck
86+
- noctx
87+
88+
# OPTIONAL - Testing (if using testify)
89+
# - testifylint
90+
# - thelper
91+
92+
settings:
93+
govet:
94+
enable:
95+
- shadow
96+
# - fieldalignment # Enable for performance-critical code
97+
settings:
98+
shadow:
99+
strict: true
100+
101+
errcheck:
102+
check-type-assertions: true
103+
check-blank: true
104+
exclude-functions:
105+
- io.Copy(*bytes.Buffer)
106+
- io.Copy(os.Stdout)
107+
- (*net/http.ResponseWriter).Write
108+
109+
staticcheck:
110+
checks:
111+
- "all"
112+
- "-SA1019" # Deprecation warnings (noisy during refactoring)
113+
- "-ST1000" # Package comment requirements
114+
- "-ST1003" # Underscore naming (conflicts with protobuf)
115+
- "-ST1016" # Receiver naming rules
116+
117+
goconst:
118+
min-len: 3
119+
min-occurrences: 3
120+
ignore-string-values:
121+
- 'http.*'
122+
- '^test.*'
123+
- '.*\.proto$'
124+
125+
godoclint:
126+
default: basic
127+
disable:
128+
- require-pkg-doc
129+
130+
sloglint:
131+
no-global: "all"
132+
static-msg: true
133+
key-naming-case: "snake"
134+
forbidden-keys:
135+
- time
136+
- level
137+
- msg
138+
- source
139+
140+
misspell:
141+
locale: US
142+
mode: restricted
143+
ignore-rules:
144+
- referer
145+
- kubernetes
146+
- grpc
147+
- protobuf
148+
149+
dupl:
150+
threshold: 100
151+
152+
nestif:
153+
min-complexity: 4
154+
155+
nilnil:
156+
only-two: true
157+
detect-opposite: true
158+
159+
gosec:
160+
excludes:
161+
- G104 # Duplicate of errcheck
162+
includes:
163+
- G201 # SQL injection
164+
- G202 # SQL injection
165+
- G204 # Command injection
166+
- G301 # File permissions
167+
- G302 # File permissions
168+
- G304 # File inclusion
169+
- G401 # Weak crypto
170+
- G402 # TLS InsecureSkipVerify
171+
172+
errorlint:
173+
errorf: true
174+
asserts: true
175+
comparison: true
176+
177+
revive:
178+
rules:
179+
# Error handling
180+
- name: error-return
181+
- name: error-strings
182+
- name: error-naming
183+
184+
# Code quality
185+
- name: if-return
186+
- name: increment-decrement
187+
- name: indent-error-flow
188+
- name: superfluous-else
189+
- name: unreachable-code
190+
191+
# Style
192+
- name: var-naming
193+
- name: range
194+
- name: receiver-naming
195+
- name: blank-imports
196+
- name: context-as-argument
197+
- name: dot-imports
198+
- name: empty-block
199+
200+
# Disable noisy rules
201+
- name: exported
202+
disabled: true
203+
- name: package-comments
204+
disabled: true
205+
- name: unused-parameter
206+
disabled: true
207+
208+
gocritic:
209+
enabled-tags:
210+
- diagnostic
211+
- style
212+
- performance
213+
disabled-checks:
214+
- commentFormatting
215+
- whyNoLint
216+
217+
exclusions:
218+
warn-unused: true
219+
220+
presets:
221+
- common-false-positives
222+
- std-error-handling
223+
224+
rules:
225+
# Test file exclusions
226+
- path: '_test\.go'
227+
linters:
228+
- dupl
229+
- errcheck
230+
- nestif
231+
- goconst
232+
- gosec
233+
- funlen
234+
- gocyclo
235+
236+
# Generated code
237+
- path: '\.pb\.go$'
238+
linters:
239+
- all
240+
241+
- path: 'mock_.+\.go$'
242+
linters:
243+
- all
244+
245+
# Long lines in go:generate
246+
- linters:
247+
- lll
248+
source: '^//go:generate '
249+
250+
# SQL linter false positives for repository pattern
251+
- text: "Rows/Stmt was not closed"
252+
path: _repository\.go$
253+
linters:
254+
- sqlclosecheck
255+
256+
issues:
257+
max-issues-per-linter: 0
258+
max-same-issues: 50
259+
uniq-by-line: true
260+
261+
# For gradual adoption on legacy codebases
262+
# new-from-rev: HEAD
263+
# new-from-merge-base: main
264+
265+
severity:
266+
default: error
267+
268+
rules:
269+
# Informational linters
270+
- linters:
271+
- dupl
272+
- goconst
273+
severity: info
274+
275+
# Security linters use their own severity
276+
- linters:
277+
- gosec
278+
severity: "@linter"

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package go_databases
1+
package godatabases
22

33
import "errors"
44

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/go-redis/redis/v8 v8.11.5
77
github.com/jackc/pgx/v5 v5.7.6
88
go.mongodb.org/mongo-driver v1.17.4
9-
golang.org/x/net v0.44.0
9+
golang.org/x/net v0.46.0
1010
gorm.io/gorm v1.31.0
1111
)
1212

@@ -19,13 +19,13 @@ require (
1919
github.com/jackc/puddle/v2 v2.2.2 // indirect
2020
github.com/jinzhu/inflection v1.0.0 // indirect
2121
github.com/jinzhu/now v1.1.5 // indirect
22-
github.com/klauspost/compress v1.18.0 // indirect
22+
github.com/klauspost/compress v1.18.1 // indirect
2323
github.com/montanaflynn/stats v0.7.1 // indirect
2424
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
2525
github.com/xdg-go/scram v1.1.2 // indirect
2626
github.com/xdg-go/stringprep v1.0.4 // indirect
2727
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
28-
golang.org/x/crypto v0.42.0 // indirect
28+
golang.org/x/crypto v0.43.0 // indirect
2929
golang.org/x/sync v0.17.0 // indirect
30-
golang.org/x/text v0.29.0 // indirect
30+
golang.org/x/text v0.30.0 // indirect
3131
)

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGC
3333
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
3434
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
3535
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
36+
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
37+
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
3638
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
3739
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
3840
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
@@ -75,6 +77,8 @@ golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
7577
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
7678
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
7779
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
80+
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
81+
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
7882
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
7983
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8084
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -83,6 +87,8 @@ golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
8387
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
8488
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
8589
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
90+
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
91+
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
8692
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8793
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8894
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
@@ -106,6 +112,8 @@ golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
106112
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
107113
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
108114
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
115+
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
116+
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
109117
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
110118
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
111119
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

mongodb/collection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (c Collection) CreateCollection(database *mongo.Database) (
4747
collection = database.Collection(c.name)
4848

4949
// Create the indexes
50-
if err = c.createIndexes(collection); err != nil {
51-
return nil, err
50+
if createErr := c.createIndexes(collection); createErr != nil {
51+
return nil, createErr
5252
}
5353

5454
return collection, nil

mongodb/connection.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package mongodb
33
import (
44
"sync"
55

6-
godatabases "github.com/ralvarezdev/go-databases"
76
"go.mongodb.org/mongo-driver/mongo"
87
"go.mongodb.org/mongo-driver/mongo/options"
98
"golang.org/x/net/context"
9+
10+
godatabases "github.com/ralvarezdev/go-databases"
1011
)
1112

1213
type (

mongodb/index.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ func NewFieldIndex(name string, order Order) *FieldIndex {
2222
// NewUniqueIndex creates a new unique field index model
2323
func NewUniqueIndex(fieldIndex FieldIndex, unique bool) *mongo.IndexModel {
2424
return &mongo.IndexModel{
25-
Keys: bson.D{{fieldIndex.name, fieldIndex.order.OrderInt()}},
25+
Keys: bson.D{{Key: fieldIndex.name, Value: fieldIndex.order.OrderInt()}},
2626
Options: options.Index().SetUnique(unique),
2727
}
2828
}
2929

3030
// NewTTLIndex creates a new TTL index model
3131
func NewTTLIndex(fieldName string, expireAfterSeconds int32) *mongo.IndexModel {
3232
return &mongo.IndexModel{
33-
Keys: bson.D{{fieldName, 1}},
33+
Keys: bson.D{{Key: fieldName, Value: 1}},
3434
Options: options.Index().SetExpireAfterSeconds(expireAfterSeconds),
3535
}
3636
}

0 commit comments

Comments
 (0)