Runtime Lifecycle
Responsibility
cmd/flaggo/main.go (runServer) and cmd/flaggo-web/main.go own process
startup, signal handling, graceful shutdown, and resource cleanup.
Backend startup
- Load config; panic on invalid config.
- Create logger, metrics, health handler.
- Select store: memory (ready), postgres (connect + migrate; degraded on failure), or neither (degraded).
- Build router; if store usable, attach
FlagsHandler. - Start HTTP server in a goroutine.
- Block on SIGINT/SIGTERM.
Degraded mode
If Postgres is unavailable, the backend logs the error, sets readiness false,
and continues serving health/metrics only. See
openwiki/operations/health-and-readiness.md.
Graceful shutdown
On signal: log, set readiness false, call server.Shutdown(ctx) with
ShutdownTimeout (default 10s), then close the store. In-flight requests get
the timeout budget to complete.
Frontend
Same pattern: start server, block on signal, graceful shutdown. Readiness depends on backend probe.
Related
openwiki/configuration/environment.mdopenwiki/operations/health-and-readiness.mdopenwiki/storage/storage-layer.md