Documentation
¶
Index ¶
Constants ¶
View Source
const ( // EndpointFieldName is the command-line flag for health check endpoint path. EndpointFieldName = "server.http.routes.health_check" // EndpointDefault is the default path for health checks. EndpointDefault = "/health-check" )
Variables ¶
View Source
var Component = &component.Component{ Dependencies: component.Components{ chi.Component, }, Init: component.StepFunc(func(container container.Container) error { return container.Provide(NewConfig) }), BindFlags: component.BindFlags(func(flagSet flag.FlagSet, container container.Container) error { return container.Invoke(func(config *Config) { flagSet.StringVar(&config.Endpoint, EndpointFieldName, EndpointDefault, "path for liveness test endpoint") }) }), Configuration: component.StepFunc(func(container container.Container) error { return container.Invoke(Configuration) }), PreExecute: component.StepFunc(func(container container.Container) error { return container.Invoke(func(config *Config, r http.Router, logger logger.Logger) { logger.Infof("[chi.router] add health endpoint - '%s'", config.Endpoint) r.Use(http.MiddlewareFunc(middleware.Heartbeat(config.Endpoint))) }) }), }
Component adds a health check endpoint to the HTTP router using chi's heartbeat middleware. It depends on chi.Component for the router.
Usage:
compogo.WithComponents(
http.Component,
chi.Component,
health_check.Component,
)
Health check responds with 200 OK at: /health-check (configurable)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Endpoint string
}
Config holds the health check endpoint configuration.
func Configuration ¶
func Configuration(config *Config, configurator configurator.Configurator) *Config
Configuration applies configuration values to the Config struct. It reads from the provided configurator and sets defaults if values are not present.
Click to show internal directories.
Click to hide internal directories.