Coding Standards
Naming
- Packages MUST be lowercase and concise.
- Exported identifiers MUST use
PascalCase. - Unexported identifiers MUST use
camelCase. - Error variables SHOULD follow
Err<Meaning>naming. - Handler names SHOULD reflect resource + action (for example:
CreateBooking,GetUser).
Error Handling
- Functions MUST return early on errors.
- Propagated errors SHOULD include context using
%w. - Handlers MUST map domain/runtime errors to stable HTTP status codes.
- Production responses MUST NOT expose sensitive internals.
if err != nil {
return fmt.Errorf("load policy by id: %w", err)
}
Logging
- Logs MUST NOT include passwords, OTPs, tokens, or secrets.
- Logs SHOULD include request-scoped context when available.
FATALSHOULD be reserved for startup-blocking failures.
Context and Timeouts
- External calls (DB/cache/HTTP/AI) MUST use bounded timeouts.
- Request-scoped context SHOULD be passed through service/data boundaries.
- Long request paths MUST avoid unbounded
context.Background().
Middleware Order
Use deterministic middleware order in server setup:
- security headers
- panic recovery
- CORS
- compression / etag
- request logging
- rate limiting
Enable logging/limiting through config flags where possible.