<One sentence: what this Go service does.>
Stack
- Go
; HTTP: <net/http + chi | standard library mux> - DB: <PostgreSQL via pgx + sqlc>; config from environment
Commands
- Run:
go run ./cmd/<service> - Tests:
go test ./...(race detector:go test -race ./...; one:go test ./internal/orders -run TestRefund -v) - Lint:
golangci-lint run - Format:
gofmt -w .(orgoimports -w .) - Generate:
go generate ./...<sqlc, mocks> - Vulnerabilities:
govulncheck ./...
Layout
cmd/<service>/main.gowiring onlyinternal/<domain>/handlers, services, storage per domain; nothing outside the module importsinternal/migrations/SQL migrations
Rules
- Errors: return them, wrap with context (
fmt.Errorf("load order %d: %w", id, err)), check witherrors.Is/As. No panics for expected failures. - Every blocking call takes a
context.Contextas the first parameter and respects cancellation. - No goroutine without a clear owner and shutdown path; use
errgroupfor fan-out. - Accept interfaces, return structs; define interfaces where they are used.
- Table-driven tests with
t.Run; usehttptestfor handlers. - Do not edit generated files (
*.sql.go, mocks); change the source and regenerate.
Definition of done
gofmt,golangci-lint run,go test -race ./...pass; generated code up to date.