health

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package health implements independent liveness, readiness and startup registries with bounded dependency checking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check func(context.Context) error

Check must honor ctx. A misbehaving callback is isolated to at most one active invocation per registered check.

func Kafka

func Kafka(admin kafka.Admin) Check

Kafka verifies actual broker metadata availability through either administration adapter.

func Ping

func Ping(p Pinger) Check

Ping adapts a dependency client without importing its optional driver.

type Pinger

type Pinger interface{ Ping(context.Context) error }

Pinger is satisfied by the SQL and Redis SDK clients.

type Registry

type Registry struct {
	Timeout  time.Duration
	OnResult func(context.Context, string, Result, error)
	// contains filtered or unexported fields
}

Registry supports concurrent Run and Register. Configure Timeout/OnResult before serving concurrent requests.

func (*Registry) Handler

func (r *Registry) Handler() http.Handler

Handler returns HTTP 200/503 with bounded, diagnostic-free JSON status.

func (*Registry) Register

func (r *Registry) Register(name string, c Check) error

Register rejects duplicate/empty dependency names.

func (*Registry) Run

func (r *Registry) Run(ctx context.Context) Report

Run executes checks in parallel, returning by each check's timeout even if a callback ignores cancellation. A timed-out callback retains its one invocation slot until it exits; later checks report busy instead of creating runaway goroutines.

type Report

type Report struct {
	Healthy bool              `json:"healthy"`
	Checks  map[string]Result `json:"checks"`
}

Report aggregates configured dependency checks. Use an empty registry for dependency-independent liveness.

type Result

type Result struct {
	Healthy  bool          `json:"healthy"`
	Duration time.Duration `json:"duration_ns"`
	Reason   string        `json:"reason,omitempty"`
}

Result contains only safe status metadata; raw dependency errors are never exposed by Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL