https://github.com/dozyio/conncheck
A Go Linter for DB connections
https://github.com/dozyio/conncheck
go golang linter
Last synced: 6 months ago
JSON representation
A Go Linter for DB connections
- Host: GitHub
- URL: https://github.com/dozyio/conncheck
- Owner: dozyio
- License: mit
- Created: 2023-11-04T12:57:37.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-11T17:33:35.000Z (almost 2 years ago)
- Last Synced: 2025-02-16T03:33:00.321Z (8 months ago)
- Topics: go, golang, linter
- Language: Go
- Homepage:
- Size: 41 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# conncheck - Go linter for db configuration

[](https://github.com/dozyio/conncheck/actions/workflows/release.yml)
[](https://goreportcard.com/report/github.com/dozyio/conncheck)
[](https://coveralls.io/github/dozyio/conncheck?branch=main)
[](LICENSE)## Installing
`go install github.com/dozyio/conncheck/cmd/conncheck@latest`
## Running
`conncheck ./...`
### Options
`-minsec` The minimum seconds for SetConnMaxLifetime (default 60). This is a
best effort static check but can be unreliable as the value is often set at
runtime.`-packages` A comma-separated list of packages to trigger linting (default database/sql,gorm.io/gorm,github.com/jmoiron/sqlx)
`-timeunits` A comma-separated list of time units to validate against (default Second,Minute,Hour)
`-printast` Print the AST, useful for debugging
## Linting
Currently the linter only checks [`db.SetConnMaxLifetime`](https://pkg.go.dev/database/sql#DB.SetConnMaxLifetime).
### db.SetConnMaxLifetime()
Checks that [`db.SetConnMaxLifetime`](https://pkg.go.dev/database/sql#DB.SetConnMaxLifetime)
is set to a reasonable value to optimise performance. `SetConnMaxLifetime`
accepts a `time.Duration` that is in nanoseconds but is often configured
incorrectly. This can lead to performance issues such as a new connection on
every request. In production, we saw a 5x increase in throughput when
`db.SetConnMaxLifetime` was configured correctly.## Recommendations
* When reading the value for `SetConnMaxLifetime` from a configuration file, use
`time.ParseDuration()` to ensure a time unit is set.