health

package
v3.0.0-...-1e29e98 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 7 Imported by: 0

README

health

health package creates a generic health check client to determine an applications (not just APIs) ability to perform the required function.

import (
    ...
    "context"

    "github.com/ONSdigital/dp-api-clients-go/v3/health"
    ...
)

func main() {
    ...
    // Create new health check (dp-net/http) client, this will set the '/health'
    // and '/healthcheck' as endpoints that are not retriable
    hcClient := health.NewClient(<name>, <url>)

    ctx := context.Background()

    // Check state of external service
    checkObj, err := hcClient.Checker(ctx)
    if err != nil {
        ...
    }

    ...
}

Alternatevely, if you already have a Clienter (instance of dp-net/http Clienter), you can reuse it in your healthcheck client, like so:

    ...
    hcClient := health.NewClientWithClienter(<name>, <url>, <clienter> dphttp.Clienter)
    ...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StatusMessage contains a map of messages to service response statuses
	StatusMessage = map[string]string{
		health.StatusOK:       " is ok",
		health.StatusWarning:  " is degraded, but at least partially functioning",
		health.StatusCritical: " functionality is unavailable or non-functioning",
	}
)

Functions

func CreateCheckState

func CreateCheckState(service string) (check health.CheckState)

CreateCheckState creates a new check state object

Types

type Client

type Client struct {
	Client dphttp.Clienter
	URL    string
	Name   string
}

Client represents an app client

func NewClient

func NewClient(name, url string) *Client

NewClient creates a new instance of Client with a given app url

func NewClientWithClienter

func NewClientWithClienter(name, url string, clienter dphttp.Clienter) *Client

NewClientWithClienter creates a new instance of Client with a given app name and url, and the provided clienter

func (*Client) Checker

func (c *Client) Checker(ctx context.Context, state *health.CheckState) error

Checker calls an app health endpoint and returns a check object to the caller

type ErrInvalidAppResponse

type ErrInvalidAppResponse struct {
	ExpectedCode int
	ActualCode   int
	URI          string
}

ErrInvalidAppResponse is returned when an app does not respond with a valid status

func (ErrInvalidAppResponse) Error

func (e ErrInvalidAppResponse) Error() string

Error should be called by the user to print out the stringified version of the error

Jump to

Keyboard shortcuts

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