Documentation
¶
Index ¶
- Constants
- type Config
- type Middleware
- type Option
- func WithAddr(addr string) Option
- func WithLivenessRoute(route string) Option
- func WithLogger(l health.Logger) Option
- func WithMiddleware(mw ...Middleware) Option
- func WithPort(port int) Option
- func WithReadinessRoute(route string) Option
- func WithServiceName(name string) Option
- func WithServiceVersion(version string) Option
- func WithStartupRoute(route string) Option
- type Reporter
- func (r *Reporter) Recover(next http.Handler) http.Handler
- func (r *Reporter) Run(_ context.Context) error
- func (r *Reporter) SetLiveness(_ context.Context, b bool)
- func (r *Reporter) SetReadiness(_ context.Context, b bool)
- func (r *Reporter) SetStartup(_ context.Context, b bool)
- func (r *Reporter) Stop(ctx context.Context) error
- func (r *Reporter) UpdateHealthChecks(_ context.Context, m map[string]*health.CheckResult)
Constants ¶
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 ¶
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 WithLivenessRoute ¶
WithLivenessRoute sets the liveness endpoint path. Default: "/live".
func WithLogger ¶
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 WithReadinessRoute ¶
WithReadinessRoute sets the readiness endpoint path. Default: "/ready".
func WithServiceName ¶
WithServiceName sets the service name for the /.well-known/health manifest.
func WithServiceVersion ¶
WithServiceVersion sets the service version for the /.well-known/health manifest.
func WithStartupRoute ¶
WithStartupRoute sets the startup endpoint path. Default: "/startup".
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
func New ¶
New creates an HTTP reporter with functional options.
reporter := httpserver.New(
httpserver.WithPort(9090),
httpserver.WithMiddleware(httpserver.BasicAuth("user", "pass")),
)
func NewReporter ¶
NewReporter creates an HTTP reporter from a Config struct. For functional options, use New() instead.