Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoAddCfgWhenActive is returned when you attempt to add check(s) to an already active healthcheck instance ErrNoAddCfgWhenActive = errors.New("Unable to add new check configuration(s) while healthcheck is active") // ErrAlreadyRunning is returned when you attempt to `h.Start()` an already running healthcheck ErrAlreadyRunning = errors.New("Healthcheck is already running - nothing to start") // ErrAlreadyStopped is returned when you attempt to `h.Stop()` a non-running healthcheck instance ErrAlreadyStopped = errors.New("Healthcheck is not running - nothing to stop") // ErrEmptyConfigs is returned when you attempt to add an empty slice of configs via `h.AddChecks()` ErrEmptyConfigs = errors.New("Configs appears to be empty - nothing to add") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Name string Checker ICheckable Interval time.Duration Fatal bool }
The Config struct is used for defining and configuring checks.
type Health ¶
Health contains internal go-health internal structures
func (*Health) AddCheck ¶
AddCheck is used for adding a single check definition to the current health instance.
func (*Health) AddChecks ¶
AddChecks is used for adding multiple check definitions at once (as opposed to adding them sequentially via `AddCheck()`).
func (*Health) DisableLogging ¶
func (h *Health) DisableLogging()
DisableLogging will disable all logging by inserting the noop logger
func (*Health) Failed ¶
Failed will return the basic state of overall health. This should be used when details about the failure are not needed
func (*Health) Start ¶
Start will start all of the defined health checks. Each of the checks run in their own goroutines (as `time.Ticker`).
func (*Health) State ¶
State will return a map of all current healthcheck states (thread-safe), a bool indicating whether the healthcheck has fully failed and a potential error.
The returned structs can be used for figuring out additional analytics or used for building your own status handler (as opposed to using the built-in `hc.HandlerBasic` or `hc.HandlerJSON`).
The map key is the name of the check.
type ICheckable ¶
type ICheckable interface { // Status allows you to return additional data as an `interface{}` and `error` // to signify that the check has failed. If `interface{}` is non-nil, it will // be exposed under `State.Details` for that particular check. Status() (interface{}, error) }
The ICheckable interface is implemented by a number of bundled checkers such as `MySQLChecker`, `RedisChecker` and `HTTPChecker`. By implementing the interface, you can feed your own custom checkers into the health library.
type IHealth ¶
type IHealth interface { AddChecks(cfgs []*Config) error AddCheck(cfg *Config) error Start() error Stop() error State() (map[string]State, bool, error) Failed() bool }
The IHealth interface can be useful if you plan on replacing the actual health checker with a mock during testing. Otherwise, you can set `hc.Disable = true` after instantiation.
type State ¶
type State struct { Name string `json:"name"` Status string `json:"status"` Err string `json:"error,omitempty"` // contains JSON message (that can be marshaled) Details interface{} `json:"details,omitempty"` CheckTime time.Time `json:"check_time"` }
The State struct contains the results of the latest run of a particular check.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
simple-http-server
This is a simple example demonstrating the simplest steps necessary for integrating the healthcheck lib into a basic HTTP service.
|
This is a simple example demonstrating the simplest steps necessary for integrating the healthcheck lib into a basic HTTP service. |
Code generated by counterfeiter.
|
Code generated by counterfeiter. |