health
Thread-safe health and readiness registry with k8s-style probes, framework adapters and ready-made checkers.
go get github.com/ubgo/health
- Language
- Go
- Go version
- 1.24
- Core deps
- 0 direct
- Latest tag
- v0.1.0
- License
- Apache-2.0
- Go modules
- 13
How it fits together
Code from the README
reg := health.NewRegistry()
reg.Register(healthredis.New("cache", redisClient)) // CHECKER
reg.Register(healthpostgres.New("db", pgxPool)) // CHECKER
healthotel.Register(reg) // OBSERVER
healthgin.Mount(r, reg) // RENDERERpackage main
import (
"context"
"log"
"time"
"github.com/ubgo/health"
)
type pingChecker struct{ name string }
func (p *pingChecker) Name() string { return p.name }
func (p *pingChecker) Check(ctx context.Context) health.Result {
// Run your dependency check here. Set Status, Error, Latency, etc.
return health.Result{Status: health.StatusUp}
}
func main() {
reg := health.NewRegistry()
_ = reg.Register(&pingChecker{name: "db"})
_ = reg.Register(&pingChecker{name: "cache"})
ctx := context.Background()
reg.Start(ctx, 30*time.Second) // background re-checks every 30s
defer reg.Stop()
snap := reg.SnapshotForProbe(health.ProbeReadiness)
log.Printf("ready=%s", snap.Status)
}reg.Subscribe(func(name string, r health.Result) {
if r.Status == health.StatusDown {
slack.Notify("check failed: " + name)
}
})From the health README.
At a glance (from the README)
| Adapter | Module path |
|---|---|
health-nethttp | github.com/ubgo/health/contrib/health-nethttp |
health-gin | github.com/ubgo/health/contrib/health-gin |
health-chi | github.com/ubgo/health/contrib/health-chi |
health-echo | github.com/ubgo/health/contrib/health-echo |
health-fiber | github.com/ubgo/health/contrib/health-fiber |