--- description: Go conventions and patterns for this project globs: "**/*.go" alwaysApply: 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: ```go 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/uuid` for all UUID types. - Model structs use `uuid.UUID`, not `string`, 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](https://sqlc.dev/) to generate type-safe Go from SQL. Write annotated SQL in `internal/store/queries/*.sql`; run `task sqlc` to regenerate. Never hand-write query code in Go — edit the `.sql` source instead. ## Testing - Use the standard `testing` package. No external assertion libraries. - Test functions follow `TestTypeName_MethodName` naming