HTTP health check handler with parallel goroutine-per-check execution, 5 s request-derived timeout, and two-level criticality (LevelCritical → 503, LevelDegraded → 200). What's included: - `Checkable` interface (HealthCheck / Name / Priority) and `Level` type with LevelCritical and LevelDegraded constants - `NewHandler(logger, checks...)` returning http.Handler; runs all checks concurrently via buffered channel, returns JSON with per-component status and latency - `ComponentStatus` and `Response` types for the JSON response body Tested-via: todo-api POC integration Reviewed-against: docs/adr/
health
Stdlib http.Handler for service health checks. Runs all checks concurrently and returns a JSON summary.
Install
go get code.nochebuena.dev/go/health
Usage
handler := health.NewHandler(logger, db, cache, queue)
r.Get("/health", handler)
Response
{
"status": "UP",
"components": {
"db": {"status": "UP", "latency": "1.2ms"},
"cache": {"status": "DOWN", "latency": "5ms", "error": "connection refused"}
}
}
| Overall status | HTTP code | Condition |
|---|---|---|
UP |
200 | All checks pass |
DEGRADED |
200 | One or more LevelDegraded checks fail; no critical failures |
DOWN |
503 | One or more LevelCritical checks fail |
Implementing Checkable
func (d *DB) HealthCheck(ctx context.Context) error { return d.pool.PingContext(ctx) }
func (d *DB) Name() string { return "postgres" }
func (d *DB) Priority() health.Level { return health.LevelCritical }
Logger
health.Logger is a duck-typed interface satisfied by logz.Logger without importing it.
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, err error, args ...any)
WithContext(ctx context.Context) Logger
}
Description
Releases
1
Release v0.9.0
Latest
Languages
Go
100%