Cookbook
Every recipe is a complete program rather than an isolated API fragment. Pick the outcome you need, copy the example into a module, and run it.
Build an API
Section titled “Build an API”CRUD APICreate, read, update, and delete an in-memory resource safely.
SQLite CRUD APIAdd persistence, typed binding, route params, and JSON responses.
Signed WebhooksLimit, authenticate, decode, and acknowledge webhook deliveries.
Health and ReadinessSeparate process health from dependency readiness.
Structured Logs with slogSend route, status, latency, and request IDs through Go's logger.
Fit Zinc into a service
Section titled “Fit Zinc into a service”Adopt Zinc in net/httpKeep a ServeMux and standard middleware while adding Zinc gradually.
Graceful ShutdownDrain active requests within a bounded shutdown window.
TimeoutsCancel slow request work through the standard request context.
Automatic TLSServe Zinc behind autocert without replacing net/http.
HTTP/2 ServerConfigure an explicit TLS-enabled standard-library server.
Reverse ProxyForward traffic through net/http/httputil with bounded transports.
Files and web UI
Section titled “Files and web UI”Embed ResourcesCompile assets into the binary and serve them through Zinc.
File UploadAccept multipart files and save them with safe server-owned paths.
File DownloadReturn files with explicit validation and response headers.
Templ UIGenerate Templ components and render them from Zinc handlers.
Templated HTML + JSRender HTML, serve assets, and progressively enhance the page.
Realtime and background work
Section titled “Realtime and background work”Server-Sent EventsPush one-way events and flush each delivery.
Streaming ResponseFlush long-running output without buffering the whole body.
WebSocketUpgrade a request for bidirectional communication.
Scheduled JobsRun cron schedules and HTTP handlers in one cleanly stopped process.
Auth and extension
Section titled “Auth and extension”JWTProtect routes and read validated claims in handlers.
Custom MiddlewareMeasure status, bytes, and timing without breaking Zinc's error flow.
