httpserver

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LivenessAffirmativeResponseCode  = http.StatusOK
	LivenessNegativeResponseCode     = http.StatusServiceUnavailable
	ReadinessAffirmativeResponseCode = http.StatusOK
	ReadinessNegativeResponseCode    = http.StatusServiceUnavailable
	StartupAffirmativeResponseCode   = http.StatusOK
	StartupNegativeResponseCode      = http.StatusServiceUnavailable
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr           string
	Port           int
	LivenessRoute  string
	ReadinessRoute string
	StartupRoute   string
	Logger         health.Logger
	Middleware     []Middleware
	ServiceName    string
	ServiceVersion string
}

Config holds the configuration for the HTTP reporter.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware wraps an http.Handler.

func BasicAuth

func BasicAuth(username, password string) Middleware

BasicAuth returns middleware that requires HTTP Basic Authentication on health endpoints. Use for external-facing deployments.

type Option

type Option func(*Config)

Option is a functional option for configuring the HTTP reporter.

func WithAddr

func WithAddr(addr string) Option

WithAddr sets the bind address. Default: "0.0.0.0".

func WithLivenessRoute

func WithLivenessRoute(route string) Option

WithLivenessRoute sets the liveness endpoint path. Default: "/live".

func WithLogger

func WithLogger(l health.Logger) Option

WithLogger sets the logger. Default: NoOpLogger.

func WithMiddleware

func WithMiddleware(mw ...Middleware) Option

WithMiddleware adds middleware to the reporter's handler chain. The first middleware in the list is the first to see the request.

func WithPort

func WithPort(port int) Option

WithPort sets the listen port. Default: 8181.

func WithReadinessRoute

func WithReadinessRoute(route string) Option

WithReadinessRoute sets the readiness endpoint path. Default: "/ready".

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the service name for the /.well-known/health manifest.

func WithServiceVersion

func WithServiceVersion(version string) Option

WithServiceVersion sets the service version for the /.well-known/health manifest.

func WithStartupRoute

func WithStartupRoute(route string) Option

WithStartupRoute sets the startup endpoint path. Default: "/startup".

type Reporter

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

func New

func New(opts ...Option) *Reporter

New creates an HTTP reporter with functional options.

reporter := httpserver.New(
    httpserver.WithPort(9090),
    httpserver.WithMiddleware(httpserver.BasicAuth("user", "pass")),
)

func NewReporter

func NewReporter(cfg Config) *Reporter

NewReporter creates an HTTP reporter from a Config struct. For functional options, use New() instead.

func (*Reporter) Recover

func (r *Reporter) Recover(next http.Handler) http.Handler

func (*Reporter) Run

func (r *Reporter) Run(_ context.Context) error

func (*Reporter) SetLiveness

func (r *Reporter) SetLiveness(_ context.Context, b bool)

func (*Reporter) SetReadiness

func (r *Reporter) SetReadiness(_ context.Context, b bool)

func (*Reporter) SetStartup

func (r *Reporter) SetStartup(_ context.Context, b bool)

func (*Reporter) Stop

func (r *Reporter) Stop(ctx context.Context) error

func (*Reporter) UpdateHealthChecks

func (r *Reporter) UpdateHealthChecks(_ context.Context, m map[string]*health.CheckResult)

Jump to

Keyboard shortcuts

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