Documentation
¶
Index ¶
- Constants
- func Serve(ctx context.Context, baseConfig *commoncfg.BaseConfig, ops ...health.Option) error
- func Start(ctx context.Context, cfg *commoncfg.BaseConfig, probes ...ProbeOption) error
- type ProbeOption
- func WithCustom(name string, handler func(http.ResponseWriter, *http.Request)) ProbeOption
- func WithHealthZ(handler func(http.ResponseWriter, *http.Request)) ProbeOption
- func WithLiveness(handler func(http.ResponseWriter, *http.Request)) ProbeOption
- func WithReadiness(handler func(http.ResponseWriter, *http.Request)) ProbeOption
- func WithStartup(handler func(http.ResponseWriter, *http.Request)) ProbeOption
Constants ¶
View Source
const ( DefReadHeaderTimeout = 2 * time.Second DefShutdownTimeout = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func Serve ¶ added in v1.9.0
Serve starts the application's liveness and readiness health check server.
This function configures and launches the health endpoints (typically `/live` and `/ready`) using the provided base configuration and optional health options.
Parameters:
- ctx: The parent context for controlling the lifecycle of the health server. Cancelling the context will stop the server gracefully.
- baseConfig: Common application configuration containing status server settings, including timeout values and standard metadata.
- ops: Optional variadic list of additional health.Option values, allowing callers to extend or override readiness configuration (e.g., register checkers).
Behavior:
- Constructs a liveness handler using disabled autostart semantics.
- Builds a readiness handler composed of the provided health options, timeout, and a status-logging listener.
- Delegates to Start(...) to launch the health server with both handlers.
- Returns an error if the server startup fails.
Returns:
- error: Non-nil if the health server fails to start; wrapped with contextual application name for improved observability.
Serve is intended for applications that follow Kubernetes-style probing conventions (liveness/readiness) or require structured health state management for orchestration and monitoring tools.
func Start ¶
func Start(ctx context.Context, cfg *commoncfg.BaseConfig, probes ...ProbeOption) error
Start starts the status server using the given probesConfig.
Types ¶
type ProbeOption ¶
type ProbeOption func(*probesConfig)
ProbeOption configures a [Handler].
func WithCustom ¶
func WithCustom(name string, handler func(http.ResponseWriter, *http.Request)) ProbeOption
func WithHealthZ ¶
func WithHealthZ(handler func(http.ResponseWriter, *http.Request)) ProbeOption
func WithLiveness ¶
func WithLiveness(handler func(http.ResponseWriter, *http.Request)) ProbeOption
func WithReadiness ¶
func WithReadiness(handler func(http.ResponseWriter, *http.Request)) ProbeOption
func WithStartup ¶
func WithStartup(handler func(http.ResponseWriter, *http.Request)) ProbeOption
Click to show internal directories.
Click to hide internal directories.