health

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package health provides utilities for monitoring the healthiness of an application.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndMonitor

type AndMonitor []Monitor

AndMonitor is a collection of [Monitor]s which follows the logical AND (&&) semantics for determining its own healthy/unhealthy state.

In the case of an error it will fail fast.

func And

func And(ms ...Monitor) AndMonitor

And is a simple helper for initializing a AndMonitor in a more functional style.

Example
var a Binary
var b Binary

and := And(&a, &b)

healthy, _ := and.Healthy(context.Background())
fmt.Println(healthy)

a.MarkHealthy()

healthy, _ = and.Healthy(context.Background())
fmt.Println(healthy)

b.MarkHealthy()

healthy, _ = and.Healthy(context.Background())
fmt.Println(healthy)
Output:

false
false
true

func (AndMonitor) Healthy

func (am AndMonitor) Healthy(ctx context.Context) (bool, error)

Healthy implements the Monitor interface.

type Binary

type Binary struct {
	// contains filtered or unexported fields
}

Binary is a Monitor which simply has 2 states: healthy or unhealthy. It is safe for concurrent use. The zero value represents an unhealthy state.

Example
var b Binary

healthy, _ := b.Healthy(context.Background())
fmt.Println(healthy)

b.MarkHealthy()

healthy, _ = b.Healthy(context.Background())
fmt.Println(healthy)

b.MarkUnhealthy()

healthy, _ = b.Healthy(context.Background())
fmt.Println(healthy)
Output:

false
true
false

func (*Binary) Healthy

func (b *Binary) Healthy(ctx context.Context) (bool, error)

Healthy implements the Monitor interface.

func (*Binary) MarkHealthy

func (b *Binary) MarkHealthy()

MarkHealthy changes that state to healthy.

func (*Binary) MarkUnhealthy

func (b *Binary) MarkUnhealthy()

MarkUnhealthy changes the state to unhealthy.

type Monitor

type Monitor interface {
	Healthy(context.Context) (bool, error)
}

Monitor represents anything which can report its current state of health.

type OrMonitor

type OrMonitor []Monitor

OrMonitor is a collection of [Monitor]s which follows the logical OR (||) semantics for determining its own healthy/unhealthy state.

It will check all [Monitor]s and if any errors are encountered they will be collected and returned as a single joined error via errors.Join.

func Or

func Or(ms ...Monitor) OrMonitor

Or is a simple helper for initializing a OrMonitor in a more functional style.

Example
var a Binary
var b Binary

or := Or(&a, &b)

healthy, _ := or.Healthy(context.Background())
fmt.Println(healthy)

a.MarkHealthy()

healthy, _ = or.Healthy(context.Background())
fmt.Println(healthy)

b.MarkHealthy()

healthy, _ = or.Healthy(context.Background())
fmt.Println(healthy)
Output:

false
true
true

func (OrMonitor) Healthy

func (om OrMonitor) Healthy(ctx context.Context) (bool, error)

Healthy implements the Monitor interface.

Jump to

Keyboard shortcuts

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