Documentation
¶
Index ¶
- func Go(ctx context.Context, log *slog.Logger, name string, cancel context.CancelFunc, ...)
- func LivenessHandler() http.HandlerFunc
- func ReadinessHandler(state *HealthState, checks ...func(ctx context.Context) error) http.HandlerFunc
- func RecoverMiddleware(log *slog.Logger) func(http.Handler) http.Handler
- func RunHealthCheck(addr string)
- type HealthState
- type Lane
- type Option
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Go ¶
func Go(ctx context.Context, log *slog.Logger, name string, cancel context.CancelFunc, fn func(ctx context.Context))
Go runs fn in a goroutine with structured panic recovery. On panic: logs stack trace and calls cancel to propagate failure up. Use this for goroutines that are critical to service operation.
func LivenessHandler ¶
func LivenessHandler() http.HandlerFunc
LivenessHandler always returns 200. A running process is a live process.
func ReadinessHandler ¶
func ReadinessHandler(state *HealthState, checks ...func(ctx context.Context) error) http.HandlerFunc
ReadinessHandler returns 200 when the app is ready and all checks pass, 503 otherwise. Pass check functions for external dependencies (e.g., db.PingContext).
func RecoverMiddleware ¶
RecoverMiddleware wraps HTTP handlers with panic recovery. On panic: logs structured context and returns 500. Does NOT cancel app context — a single handler panic is recoverable; the service continues.
func RunHealthCheck ¶
func RunHealthCheck(addr string)
RunHealthCheck exits the process with 0 (healthy) or 1 (unhealthy) when "healthcheck" is passed as the first argument. Call at the top of main() before any initialization to support CMD-based container health probes.
Types ¶
type HealthState ¶
type HealthState struct {
// contains filtered or unexported fields
}
HealthState tracks the application's readiness. Liveness is always true — if the process is running, it's alive.
func (*HealthState) IsReady ¶
func (h *HealthState) IsReady() bool
func (*HealthState) SetReady ¶
func (h *HealthState) SetReady(v bool)
type Lane ¶
type Lane struct {
// contains filtered or unexported fields
}
Lane coordinates the lifecycle of one or more Runners. It handles signal interception, concurrent startup, health state, and ordered graceful shutdown. Dependency wiring is the caller's responsibility.
func (*Lane) AddRunner ¶
AddRunner appends runners. Registration order determines startup order and reverse-order (LIFO) shutdown order.
func (*Lane) Health ¶
func (l *Lane) Health() *HealthState
Health returns the HealthState so callers can pass it to ReadinessHandler.
type Option ¶
type Option func(*Lane)
Option configures a Lane.
func WithShutdownTimeout ¶
WithShutdownTimeout overrides the default 30s shutdown timeout.