health

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package health provides utilitis to check the health of a service at a regular interval.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Always

type Always bool

Always is a health checker that always returns the same value. It is used when no health check is specified.

func (Always) Check

func (a Always) Check() <-chan Result

Check always returns a nil channel. Receiving from this channel will block forever.

func (Always) Launch

func (a Always) Launch(func(w http.ResponseWriter, r *http.Request) (*url.URL, error))

Launch does nothing.

func (Always) Up

func (a Always) Up() bool

Up always returns true.

type Checker

type Checker interface {
	Launch(remoteFunc func(w http.ResponseWriter, r *http.Request) (*url.URL, error))
	Up() bool
	Check() <-chan Result
}

Checker is the interface that wraps the basic methods for a health checker.

type Health

type Health struct {
	Info
	http.Handler
	// contains filtered or unexported fields
}

Health periodically checks the health of a service.

func New

func New(info Info) *Health

New creates a new Health.

func (*Health) Check

func (h *Health) Check() <-chan Result

Check returns a channel that will receive the health result on each check.

func (*Health) Launch

func (h *Health) Launch(remoteFunc func(w http.ResponseWriter, r *http.Request) (*url.URL, error))

Launch starts the periodic health check. A remoteFunc is used to get the service's remote URL in the case that the remote URL is dynamic. This remote is then used to construct the health remote URL that will be used for the health check.

func (*Health) Up

func (h *Health) Up() bool

Up returns whether the service is up.

type Info

type Info struct {
	Path     string        `yaml:"path"`
	TLS      bool          `yaml:"tls"`
	Interval time.Duration `yaml:"interval"`
	Timeout  time.Duration `yaml:"timeout"`
	Method   string        `yaml:"method"`
}

Info describes a service Health capability.

type Result

type Result struct {
	Up       bool
	Err      error
	Endpoint string
}

Result is the result of a health check.

func (Result) LogValue

func (h Result) LogValue() slog.Value

LogValue returns a slog.Value for the result, ensuring that the error is displayed properly.

Jump to

Keyboard shortcuts

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