Documentation ¶
Overview ¶
HTTP handler that retrieves health status of the application
Index ¶
Examples ¶
Constants ¶
const (
DefaultTimeout = 3 * time.Second
)
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(_ context.Context) error { return nil }, }, } mux := http.NewServeMux() h := health.NewHealth(health.WithChecks(checks...)) mux.Handle(health.HealthEndpoint, h.Handler()) }
Output:
func (*Health) 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