health

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 9 Imported by: 0

README

health

import "github.com/induzo/gocom/http/health"

HTTP handler that retrieves health status of the application

Index

Constants

const (
    DefaultTimeout = 3 * time.Second
)
const (
    HealthEndpoint = "/sys/health" // URL used by infra team
)

type CheckConfig

CheckConfig are the parameters used to run each check.

type CheckConfig struct {
    Name    string
    CheckFn func(ctx context.Context) error
    Timeout time.Duration
}

type CheckError

CheckError is an error returned when the health check function returns an error.

type CheckError struct {
    // contains filtered or unexported fields
}
func (*CheckError) Error
func (e *CheckError) Error() string

type Health

Health provides http.Handler that retrieves the health status of the application based on the provided checks.

type Health struct {
    // contains filtered or unexported fields
}
Example

Using Health HTTP handler

package main

import (
	"context"
	"net/http"
	"time"

	"github.com/induzo/gocom/http/health"
)

func main() {
	checks := []health.CheckConfig{
		{
			Name:    "lambda",
			Timeout: 1 * time.Second, // Optional to specify timeout
			CheckFn: func(ctx context.Context) error {
				return nil
			},
		},
	}

	mux := http.NewServeMux()

	h := health.NewHealth(health.WithChecks(checks...))

	mux.Handle(health.HealthEndpoint, h.Handler())
}

func NewHealth
func NewHealth(opts ...Option) *Health

NewHealth returns a new Health with the provided options.

func (*Health) Handler
func (h *Health) Handler() http.Handler

Handler returns a http.Handler that retrieves the health status of the application based on the provided check functions.

func (*Health) RegisterCheck
func (h *Health) RegisterCheck(conf CheckConfig)

RegisterCheck registers a check to be run as part of the health check.

type Option

Option is the options type to configure Health.

type Option func(*Health)
func WithChecks
func WithChecks(checkConf ...CheckConfig) Option

WithChecks adds the checks to be run as part of the health check.

type Response

Response is the health check handler response.

type Response struct {
    Error        string `json:"error,omitempty"`
    ErrorMessage string `json:"error_message,omitempty"`
}

type TimeoutError

TimeoutError is an error returned when the health check function exceeds the timeout duration.

type TimeoutError struct {
    // contains filtered or unexported fields
}
func (*TimeoutError) Error
func (e *TimeoutError) Error() string

Generated by gomarkdoc

Documentation

Overview

HTTP handler that retrieves health status of the application

Index

Examples

Constants

View Source
const (
	DefaultTimeout = 3 * time.Second
)
View Source
const (
	HealthEndpoint = "/sys/health" // URL used by infra team
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckConfig

type CheckConfig struct {
	Name    string
	CheckFn func(ctx context.Context) error
	Timeout time.Duration
}

CheckConfig are the parameters used to run each check.

type CheckError

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

CheckError is an error returned when the health check function returns an error.

func (*CheckError) Error

func (e *CheckError) Error() string

type Health

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

Health provides http.Handler that retrieves the health status of the application based on the provided checks.

Example

Using Health HTTP handler

package main

import (
	"context"
	"net/http"
	"time"

	"github.com/induzo/gocom/http/health"
)

func main() {
	checks := []health.CheckConfig{
		{
			Name:    "lambda",
			Timeout: 1 * time.Second, // Optional to specify timeout
			CheckFn: func(ctx context.Context) error {
				return nil
			},
		},
	}

	mux := http.NewServeMux()

	h := health.NewHealth(health.WithChecks(checks...))

	mux.Handle(health.HealthEndpoint, h.Handler())
}
Output:

func NewHealth

func NewHealth(opts ...Option) *Health

NewHealth returns a new Health with the provided options.

func (*Health) Handler

func (h *Health) Handler() http.Handler

Handler returns a http.Handler that retrieves the health status of the application based on the provided check functions.

func (*Health) RegisterCheck

func (h *Health) RegisterCheck(conf CheckConfig)

RegisterCheck registers a check to be run as part of the health check.

type Option

type Option func(*Health)

Option is the options type to configure Health.

func WithChecks

func WithChecks(checkConf ...CheckConfig) Option

WithChecks adds the checks to be run as part of the health check.

type Response

type Response struct {
	Error        string `json:"error,omitempty"`
	ErrorMessage string `json:"error_message,omitempty"`
}

Response is the health check handler response.

type TimeoutError

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

TimeoutError is an error returned when the health check function exceeds the timeout duration.

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

Jump to

Keyboard shortcuts

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