Help us shape the future of Go! Take the 2026 Go Developer Survey

status

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 16 Imported by: 9

Documentation

Index

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

func Serve(ctx context.Context, baseConfig *commoncfg.BaseConfig, ops ...health.Option) error

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:

  1. Constructs a liveness handler using disabled autostart semantics.
  2. Builds a readiness handler composed of the provided health options, timeout, and a status-logging listener.
  3. Delegates to Start(...) to launch the health server with both handlers.
  4. 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

Jump to

Keyboard shortcuts

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