boilerplate

module
v0.0.0-...-d3a19af Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT

README

Records Service Boilerplate

Design

Connection Pooling

Only open a connection to your database w/ gorm.Open() just once in your code and pass it everywhere from a global variable. Gorm's underlying sql.DB() interface will automatically use connection pooling for every transaction. To use connection pooling, it is important to configure the following values:

sqlDB.SetConnMaxIdleTime(time.Minute * 5)
sqlDB.SetConnMaxLifetime(time.Minute * 5)
sqlDB.SetMaxOpenConns(10)
sqlDB.SetMaxIdleConns(0)
Loggnig Do's and Don'ts
  • Establish clear logging objectives
  • Use log levels correctly
  • Structure your logs
  • Write meaningful log entries
  • Sample your logs
  • Use canonical log lines
  • Aggregate and centralize your logs
  • Establish log retention policies
  • Protect your logs
  • Don't log sensitive data
  • Don't ignore the performance cost of logging
  • Don't use logs for monitoring

Testing

  • To generate test coverage of a specific package: go test -cover [pkg_name]
  • To generate test coverage of the entire codebase: go test -cover ./...
  • To generate test coverage and open visuals in browser: go test -coverprofile=coverage.out ./... ; go tool cover -html=coverage.out

Directories

Path Synopsis
api
cmd
pkg
records
db
Package db is a generated GoMock package.
Package db is a generated GoMock package.
service
Package service is a generated GoMock package.
Package service is a generated GoMock package.

Jump to

Keyboard shortcuts

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