Documentation ¶
Index ¶
- func NewBackground(name string, initialErr error, delay, period, timeout time.Duration, ...) *bgCheck
- func NewBasic(name string, timeout time.Duration, fn CheckFn) *basicCheck
- func NewManual(name string) *manualCheck
- func ReadyHandler(healthcheck IHealthcheck) http.HandlerFunc
- func WithCheckStatusFn(fn func(checkID string, isReady Status)) func(*hcOptions)
- func WithHealthcheck(hc *Healthcheck) func(o *serverOptions)
- func WithLogger(logger *slog.Logger) func(o *serverOptions)
- func WithPort(port int) func(o *serverOptions)
- type Check
- type CheckFn
- type CheckState
- type Healthcheck
- type ICheck
- type IHealthcheck
- type ILogger
- type Report
- type Server
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBackground ¶ added in v0.4.0
func NewBackground(name string, initialErr error, delay, period, timeout time.Duration, fn CheckFn) *bgCheck
NewBackground will create a check that runs in background. Usually used for slow or expensive checks. Note: period should be greater than timeout.
hc, _ := healthcheck.New(...) hc.Register(healthcheck.NewBackground("some_subsystem"))
func NewBasic ¶
NewBasic creates a basic check. This check will only be performed when RunAllChecks is called.
hc, _ := healthcheck.New(...) hc.Register(healthcheck.NewBasic("postgres", time.Second, func(context.Context) error { ... }))
func NewManual ¶
func NewManual(name string) *manualCheck
NewManual create new check, that can be managed by client. Marked as failed by default.
hc, _ := healthcheck.New(...) check := healthcheck.NewManual("some_subsystem") check.SetError(nil) hc.Register(check) check.SetError(errors.New("service unavailable"))
func ReadyHandler ¶ added in v0.6.0
func ReadyHandler(healthcheck IHealthcheck) http.HandlerFunc
ReadyHandler build a http.HandlerFunc from healthcheck.
func WithCheckStatusFn ¶
WithCheckStatusFn will provide a function that will be called at each check changes.
func WithHealthcheck ¶
func WithHealthcheck(hc *Healthcheck) func(o *serverOptions)
func WithLogger ¶
Types ¶
type Check ¶ added in v0.5.0
type Check struct { Name string `json:"name"` State CheckState `json:"state"` Previous []CheckState `json:"previous"` }
type CheckState ¶ added in v0.5.0
type Healthcheck ¶
type Healthcheck struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ...func(*hcOptions)) (*Healthcheck, error)
func (*Healthcheck) Register ¶
func (s *Healthcheck) Register(ctx context.Context, check ICheck)
Register will register a check.
All checks should have a name. Will be better that name will contain only lowercase symbols and lodash. This is allowing to have the same name for Check and for metrics.
func (*Healthcheck) RunAllChecks ¶
func (s *Healthcheck) RunAllChecks(ctx context.Context) Report
RunAllChecks will run all check immediately.