Documentation ¶
Overview ¶
Package healthcheck provides a simple way to define health checks for external services or components. These checks are aggregated by the /status endpoint.
Index ¶
Constants ¶
const (
// StatusOK represents an OK status.
StatusOK = "OK"
)
Variables ¶
This section is empty.
Functions ¶
func CheckHTTPStatus ¶
func CheckHTTPStatus(ctx context.Context, httpClient HTTPClient, method string, url string, wantStatusCode int, timeout time.Duration, opts ...CheckOption) error
CheckHTTPStatus checks if the given HTTP request responds with the expected status code.
Types ¶
type CheckOption ¶
type CheckOption func(*checkConfig)
CheckOption is a type alias for a function able to configure HTTP healthcheck options.
func WithConfigureRequest ¶
func WithConfigureRequest(fn func(r *http.Request)) CheckOption
WithConfigureRequest allows to configure the request before it is sent.
type HTTPClient ¶
HTTPClient contains the function that performs the actual HTTP request.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the struct containng the HTTP handler function that performs the healthchecks.
func NewHandler ¶
func NewHandler(checks []HealthCheck, opts ...HandlerOption) *Handler
NewHandler creates a new instance of the healthcheck handler.
type HandlerOption ¶
type HandlerOption func(h *Handler)
HandlerOption is a type alias for a function that configures the healthcheck HTTP handler.
func WithResultWriter ¶
func WithResultWriter(w ResultWriter) HandlerOption
WithResultWriter overrides the default healthcheck result writer.
type HealthCheck ¶
type HealthCheck struct { // ID is a unique identifier for the healthcheck. ID string // Checker is the function used to perform the healthchecks. Checker HealthChecker }
HealthCheck is a structure containing the configuration for a single health check.
func New ¶
func New(id string, checker HealthChecker) HealthCheck
New creates a new instance of a health check configuration with default timeout.
type HealthChecker ¶
HealthChecker is the interface that wraps the HealthCheck method.
type ResultWriter ¶
type ResultWriter func(ctx context.Context, w http.ResponseWriter, statusCode int, data interface{})
ResultWriter is a type alias for a function in charge of writing the result of the health checks.