Skip to content

How-To Guides

These guides are practical recipes. Each one targets a single task, shows the minimum code needed to accomplish it, and links to the relevant module primer when you need the boundary rationale behind the pattern.

They assume you have already completed Getting Started and can run the reference service. If you are new to the project, finish the first-day path on Docs Home before choosing a guide.

GuideWhat it shows
Add JWT AuthWire security/jwt + middleware/auth for token-protected routes
Write Custom MiddlewareImplement a middleware.Middleware constructor with explicit deps
Connect a DatabaseInject a store primitive into handlers without app-level globals
Handle ErrorsUse contract.WriteError and NewErrorBuilder for structured responses
Graceful ShutdownWire OS signal handling with Prepare / Server / Shutdown
Health and ReadinessImplement ComponentChecker and wire /healthz + /readyz
Structured LoggingUse log.NewLogger, WithFields, and Fields in handlers
Testing HandlersTest http.HandlerFunc handlers with httptest.NewRecorder
GuideWhat it shows
Integrate AIWire x/ai provider, manage sessions, and stream completions via SSE
Build a REST ResourceUse x/rest for full CRUD with pagination, filtering, and a SQL repository
Multi-TenancyResolve tenant identity, enforce policy, and scope queries with x/tenant
Real-Time with WebSocketsUpgrade connections, manage rooms and hubs, broadcast messages with x/websocket
File Uploads and DownloadsWire x/fileapi handlers for multipart upload, streaming download, and file metadata
GuideWhat it shows
Deploy with DockerMulti-stage Dockerfile, env-var configuration, Kubernetes health probes
Observability IntegrationPrometheus metrics, structured logging, distributed tracing via x/observability
Migration and UpgradesStable root upgrade path, tracking experimental-to-stable promotion

Each guide shows one correct pattern and stops there. They do not try to cover every option or configuration knob — the module primers and module.yaml files in the source tree do that. If a guide’s code and a module’s module.yaml ever disagree, the module.yaml is the authoritative source.

Stable-root guides do not introduce x/* extensions into the canonical service path. Operations guides reference x/observability where it is the correct home for the capability — each such reference links to the extension primer for the boundary rationale.