conncheck

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 16 Imported by: 0

README

conncheck - Go linter for db configuration

Latest release CI Go Report Card Coverage Status MIT 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.

db.SetConnMaxLifetime()

Checks that 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config *Config) *analysis.Analyzer

New creates a new conncheck analyzer for golangci-lint.

func NewConncheck added in v1.1.5

func NewConncheck(config *Config) *connCheck

NewConncheck creates a new conncheck.

Types

type Config added in v1.1.2

type Config struct {
	Pkgs       stringSliceValue
	ValidUnits stringSliceValue
	MinSeconds uint64
	// contains filtered or unexported fields
}

func DefaultConfig added in v1.1.4

func DefaultConfig() *Config

DefaultConfig returns the default config for conncheck.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL