Table of contents
Part of nurago, a collection of independent Go packages for backend services.
import "github.com/tecnickcom/nurago/pkg/healthcheck/healthrun"
The check model and the parallel runner behind healthcheck, without the HTTP layer.
runner := healthrun.NewRunner([]healthrun.HealthCheck{
healthrun.New("database", db),
healthrun.New("cache", redisClient),
}, healthrun.WithTimeout(time.Second))
results := runner.Run(ctx) // map[string]error, keyed by check ID
One check model, two transports
HealthChecker, HealthCheckFunc and HealthCheck are defined here. The healthcheck types are aliases of them, so the same slice of checks registers with the HTTP /status handler and with the gRPC health service of grpcserver, with no conversion.
Every client in this module that exposes HealthCheck(context.Context) error registers without an adapter, as described on the healthcheck page.
Run semantics
- Checks run in parallel, one goroutine per check, so the run takes as long as the slowest check.
- A panicking checker is recovered, logged, and reported as
ErrCheckPanic. - A nil checker is reported as
ErrNoChecker. - With
WithTimeout, a check that overruns is reported asErrCheckTimeout.
Each failure mode has its own sentinel, so a transport can distinguish “the dependency answered with an error” from “the probe itself is broken” with errors.Is.
Outcomes are keyed by ID. Duplicate or empty IDs collapse into one entry and hide a check, and construction logs a warning when it sees one.
When to import this instead of healthcheck
When the service has no HTTP surface, or reports health over another transport. healthcheck pulls httprouter through httputil; this package uses the standard library alone.
Dependencies
This package reaches no external module: it uses only the Go standard library. make depcheck fails the build if it ever does.
Links
- Reference documentation
- Source code
- Over HTTP: healthcheck
- Over gRPC: grpcserver
- All nurago packages