servicehealthcheck

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: MIT Imports: 6 Imported by: 0

README

Health Checks for Services

  • Makes it possible to have a health check for different services (e.g. postgres, redis)

  • A service has to implement the HealthCheck interface and register the health check with servicehealthchecker.RegisterHealthCheck(hc HealthCheck, name string)

  • healthchecker does NOT cache the results but offers a struct (ConnectionState) for caching

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler() http.Handler

Handler returns the health api endpoint

func RegisterHealthCheck

func RegisterHealthCheck(hc HealthCheck, name string)

RegisterHealthCheck registers a HealthCheck that need to be routed. The name must be unique. If the health check satisfies the Initialisable interface, it is initialised before it is added.

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() (bool, error)

GetState returns the current state. That is whether the check is healthy or the error occured.

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() (bool, error)
}

HealthCheck is a health check that is initialised once and that is performed periodically and/or spontaneously.

type Initialisable

type Initialisable interface {
	Init() error
}

Jump to

Keyboard shortcuts

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