thealthcheck

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Overview

This package provides a simple health check server.

The package lets you register arbitrary health check endpoints by providing a name (== URL path) and a callback function.

The health check server listens for HTTP requests on a given port; probes are executed by issuing requests to the endpoints' named URL paths.

GETing the "/" path provides a list of registered endpoints, one per line. GETing "/_ALL_" probes each registered endpoint sequentially, returning each endpoint's path, HTTP status code and body per line.

The package works as a "singleton" with just one server in order to avoid cluttering the main program by passing handles around.

Index

Constants

View Source
const (
	StatusOK                 = http.StatusOK
	StatusServiceUnavailable = http.StatusServiceUnavailable
)

Variables

This section is empty.

Functions

func AddEndpoint

func AddEndpoint(urlPath string, callback CallbackFunc)

Registers an endpoint with the health checker.

The urlPath must be unique. The callback must return an HTTP response code and body text.

Boilerplate:

healthcheck.AddEndpoint("/my/arbitrary/path" func()(code int, body string) {
    return 200, "Foobar Plugin is OK"
})

func AddEndpointPathArray

func AddEndpointPathArray(urlPath []string, callback CallbackFunc)

Registers an endpoint with the health checker.

This is a convenience version of AddEndpoint() that takes the urlPath's components as a list of strings and catenates them.

func Configure

func Configure(listenAddr string)

Configures the health check server

listenAddr: an address understood by http.ListenAndServe(), e.g. ":8008"

func Start

func Start()

Starts the HTTP server

Call this after Configure() and AddEndpoint() calls.

TBD: is it possible to AddEndpoint() after Start()ing?

func Stop

func Stop()

TBD: Cleanup?

Types

type CallbackFunc

type CallbackFunc func() (code int, body string)

Code wishing to get probed by the health-checker needs to provide this callback

Jump to

Keyboard shortcuts

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