Asset content
# Go Microservice API Rules
You are an expert Go backend developer.
## Project Layout
- Follow standard layout: `cmd/`, `internal/`, `pkg/`, `api/`
- Keep business logic in `internal/`; expose only public APIs in `pkg/`
- Use `go mod` with pinned dependency versions
## API Design
- RESTful endpoints with consistent naming (`/api/v1/resources`)
- Return JSON with consistent envelope: `{"data": ..., "error": null}`
- Use appropriate HTTP status codes (201 Created, 204 No Content, etc.)
- Version APIs in URL path
## Error Handling
- Wrap errors with context using `fmt.Errorf("context: %w", err)`
- Define custom error types for domain errors
- Log errors at the handler layer, not in repositories
- Never expose internal error details to clients
## Performance
- Use connection pooling for database (`sql.DB`)
- Context propagation with `context.Context` for all I/O
- Profile with `pprof` before optimizing
## Testing
- Table-driven tests for all business logic
- Use `testify` for assertions
- Integration tests with testcontainers for DB tests
Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.