Documentation ¶
Index ¶
- func HealthHandler() http.HandlerFunc
- func JSONHealthHandler() http.HandlerFunc
- func ReadableHealthHandler() http.HandlerFunc
- func RegisterHealthCheck(name string, hc HealthCheck, opts ...HealthCheckOption)
- func RegisterHealthCheckFunc(name string, f HealthCheckFunc, opts ...HealthCheckOption)
- func RegisterOptionalHealthCheck(hc HealthCheck, name string, opts ...HealthCheckOption)
- type ConnectionState
- type HealthCheck
- type HealthCheckCfg
- type HealthCheckFunc
- type HealthCheckOption
- type HealthCheckResult
- type HealthState
- type Initializable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HealthHandler ¶ added in v0.1.19
func HealthHandler() http.HandlerFunc
HealthHandler returns the health endpoint for transactional processing. This Handler only checks the required health checks and returns ERR and 503 or OK and 200.
func JSONHealthHandler ¶ added in v0.1.93
func JSONHealthHandler() http.HandlerFunc
JSONHealthHandler return health endpoint with all details about service health. This handler checks all health checks. The response body contains a JSON formatted array with every service (required or optional) and the detailed health checks about them.
func ReadableHealthHandler ¶ added in v0.1.19
func ReadableHealthHandler() http.HandlerFunc
ReadableHealthHandler returns the health endpoint with all details about service health. This handler checks all health checks. The response body contains two tables (for required and optional health checks) with the detailed results of the health checks.
func RegisterHealthCheck ¶
func RegisterHealthCheck(name string, hc HealthCheck, opts ...HealthCheckOption)
RegisterHealthCheck registers a required HealthCheck. The name must be unique. If the health check satisfies the Initializable interface, it is initialized before it is added. It is not possible to add a health check with the same name twice, even if one is required and one is optional
func RegisterHealthCheckFunc ¶ added in v0.1.35
func RegisterHealthCheckFunc(name string, f HealthCheckFunc, opts ...HealthCheckOption)
RegisterHealthCheckFunc registers a required HealthCheck. The name must be unique. It is not possible to add a health check with the same name twice, even if one is required and one is optional
func RegisterOptionalHealthCheck ¶ added in v0.1.19
func RegisterOptionalHealthCheck(hc HealthCheck, name string, opts ...HealthCheckOption)
RegisterOptionalHealthCheck registers a HealthCheck like RegisterHealthCheck(hc HealthCheck, name string) but the health check is only checked for /health/check and not for /health/
Types ¶
type ConnectionState ¶
type ConnectionState struct {
// contains filtered or unexported fields
}
ConnectionState caches the result of health checks. It is concurrency-safe.
func (*ConnectionState) GetState ¶
func (cs *ConnectionState) GetState() HealthCheckResult
GetState returns the current state. That is whether the check is healthy or the error occurred.
func (*ConnectionState) LastChecked ¶
func (cs *ConnectionState) LastChecked() time.Time
LastChecked returns the time that the state was last updated or confirmed.
func (*ConnectionState) SetErrorState ¶
func (cs *ConnectionState) SetErrorState(err error)
SetErrorState sets the state to not healthy.
func (*ConnectionState) SetHealthy ¶
func (cs *ConnectionState) SetHealthy()
SetHealthy sets the state to healthy.
type HealthCheck ¶
type HealthCheck interface {
HealthCheck(ctx context.Context) HealthCheckResult
}
HealthCheck is a health check that is registered once and that is performed periodically in the background.
type HealthCheckCfg ¶ added in v0.3.7
type HealthCheckCfg struct {
// contains filtered or unexported fields
}
HealthCheckCfg is the config used per HealthCheck.
type HealthCheckFunc ¶ added in v0.1.35
type HealthCheckFunc func(ctx context.Context) HealthCheckResult
func (HealthCheckFunc) HealthCheck ¶ added in v0.1.35
func (hcf HealthCheckFunc) HealthCheck(ctx context.Context) HealthCheckResult
type HealthCheckOption ¶ added in v0.3.7
type HealthCheckOption func(cfg *HealthCheckCfg)
func UseInitErrResultTTL ¶ added in v0.3.7
func UseInitErrResultTTL(ttl time.Duration) HealthCheckOption
func UseInterval ¶ added in v0.3.7
func UseInterval(interval time.Duration) HealthCheckOption
func UseMaxWait ¶ added in v0.3.7
func UseMaxWait(maxWait time.Duration) HealthCheckOption
func UseWarmup ¶ added in v0.4.2
func UseWarmup(delay time.Duration) HealthCheckOption
UseWarmup - delays a healthcheck during warmup
type HealthCheckResult ¶ added in v0.1.19
type HealthCheckResult struct { State HealthState Msg string }
HealthCheckResult describes the result of a health check, contains the state of a service and a message that describes the state. If the state is Ok the description can be empty. The description should contain the error message if any error or warning occurred during the health check.
type HealthState ¶ added in v0.1.19
type HealthState string
HealthState describes if a any error or warning occurred during the health check of a service
const ( // Err State of a service, if an error occurred during the health check of the service Err HealthState = "ERR" // Warn State of a service, if a warning occurred during the health check of the service Warn HealthState = "WARN" // Ok State of a service, if no warning or error occurred during the health check of the service Ok HealthState = "OK" )
type Initializable ¶ added in v0.1.35
Initializable is used to mark that a health check needs to be initialized