1.1 KiB
1.1 KiB
description, globs, alwaysApply
| description | globs | alwaysApply |
|---|---|---|
| Go conventions and patterns for this project | **/*.go | false |
Go Conventions
Context
Every exported function that does I/O takes context.Context as its first argument.
Errors
- Define package-level sentinel errors for expected conditions:
var ErrNotFound = fmt.Errorf("not found")
- Wrap unexpected errors with
fmt.Errorf("doing X: %w", err)to preserve the chain. - Callers check expected errors with
errors.Is(err, store.ErrNotFound).
UUIDs
- Use
github.com/google/uuidfor all UUID types. - Model structs use
uuid.UUID, notstring, for ID fields.
Database
- Use
?parameter placeholders (MySQL style), never string interpolation. - Use
gen_random_uuid()for server-generated UUIDs (Postgres built-in). - Queries: use sqlc to generate type-safe Go from SQL.
Write annotated SQL in
internal/store/queries/*.sql; runtask sqlcto regenerate. Never hand-write query code in Go — edit the.sqlsource instead.
Testing
- Use the standard
testingpackage. No external assertion libraries. - Test functions follow
TestTypeName_MethodNamenaming