A Go service using mostly the standard library plus a small set of carefully chosen dependencies. Single binary deploy, runs on Linux.
- Language: Go 1.22+
- Module: enabled (
go.modat root) - HTTP:
net/httpstandard library +github.com/go-chi/chi/v5for routing - DB:
database/sql+github.com/jackc/pgx/v5for PostgreSQL - Logging:
log/slog(stdlib structured logging) - Testing:
testingpackage +github.com/stretchr/testify/requirefor assertions
go mod download
go run ./cmd/server # dev
go build -o bin/server ./cmd/server
go test ./... # all tests
go test -race ./... # race detector
go vet ./... # vet
gofmt -w . # format- Formatter:
gofmt(mandatory; CI fails if not formatted) - Errors: return as values, never panic in library code; wrap with
fmt.Errorf("doing X: %w", err) - Naming: idiomatic Go — short names for short scopes, descriptive for exported
- Comments: every exported identifier needs a doc comment starting with the name
- Concurrency: prefer channels for ownership transfer; use
sync.Mutexonly for protecting shared state
- Do not use
interface{}/anyunless truly necessary — prefer concrete types or generics - Do not catch panics with
recover()in normal flow — only in long-running goroutines as last-resort safety - Do not use init() for non-trivial work — explicit setup in
mainis clearer - Do not import test helpers into production packages — keep
*_test.goboundary clean - Do not use ORMs —
database/sql+pgxis sufficient and more transparent
cmd/server/main.go— entry point, wiringinternal/handlers/— HTTP handlersinternal/services/— business logicinternal/store/— DB layerinternal/config/— env-driven configmigrations/— goose-managed SQL migrationsgo.mod/go.sum— modules