srvhttp

package module
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config[T http.Handler] struct {
	Label common.Label
	Host  common.Host
	Port  common.Port
	// contains filtered or unexported fields
}

Config is the HTTP server spec (Label, Host, Port); ecfg fills before Build.

func (*Config[T]) Build

func (cfg *Config[T]) Build() (any, error)

type HTTPMetrics added in v0.21.0

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

HTTPMetrics is a singleton pool resource: contributor + shared slok Recorder for all srv-http servers. rec is an atomic.Pointer, not a plain field: RegisterMetrics can run concurrently with Observe*/AddInflightRequests from in-flight request goroutines on other srv-http.Server instances sharing this singleton — a plain metrics.Recorder field would be a data race on a 2-word interface value (torn type/data read), same class of bug [Server.err] already guards against with atomic.Error.

func (*HTTPMetrics) AddInflightRequests added in v0.21.0

func (m *HTTPMetrics) AddInflightRequests(ctx context.Context, props metrics.HTTPProperties, quantity int)

func (*HTTPMetrics) ObserveHTTPRequestDuration added in v0.21.0

func (m *HTTPMetrics) ObserveHTTPRequestDuration(ctx context.Context, props metrics.HTTPReqProperties, duration time.Duration)

func (*HTTPMetrics) ObserveHTTPResponseSize added in v0.21.0

func (m *HTTPMetrics) ObserveHTTPResponseSize(ctx context.Context, props metrics.HTTPReqProperties, sizeBytes int64)

func (*HTTPMetrics) RegisterMetrics added in v0.21.0

func (m *HTTPMetrics) RegisterMetrics(reg *prometheus.Registry) error

type MetricsContributor added in v0.21.0

type MetricsContributor interface {
	RegisterMetrics(reg *prometheus.Registry) error
}

MetricsContributor registers HTTP metrics collectors into a shared registry. Same method signature as github.com/omcrgnt/ops/metrics.MetricsContributor.

type Option added in v0.27.0

type Option[T http.Handler] func(*Server[T])

Option configures a Server at construction time, for values ecfg can't fill (e.g. middleware functions) — see New.

func WithMiddleware added in v0.27.0

func WithMiddleware[T http.Handler](mw ...func(http.Handler) http.Handler) Option[T]

WithMiddleware appends middleware run in addition to (not instead of) the metrics/gate wrapping this package always installs, closest to the real handler — see Config.Build's initFn for exact placement.

type Server added in v0.22.0

type Server[T http.Handler] struct {
	http.Server
	// contains filtered or unexported fields
}

Server is the HTTP server resource bound to handler type T. Catalog field: *Server[T] (Configurable); materialized *Server[T] is the runtime instance after Config.Build. Runtime methods: Start (returns a cleanup that stops the server), HealthCheck, ProbeReady. Close also exists (see its own doc comment) but only to shadow the embedded http.Server's promoted Close — prefer the cleanup Start returns.

func New added in v0.27.0

func New[T http.Handler](opts ...Option[T]) *Server[T]

New constructs a Server[T] with the given options applied. The catalog field holding it must be assigned this (non-nil) in the app's resources literal — left nil (the zero-value default), these options are lost when Build constructs a fresh instance. See client-grpc's Client.New.

func (*Server[T]) BuildConfig added in v0.22.0

func (t *Server[T]) BuildConfig() (app.Materializer, error)

BuildConfig returns the config spec for materialize, carrying over whatever options New was called with.

func (*Server[T]) Close added in v0.22.0

func (t *Server[T]) Close() error

Close shadows the http.Server.Close this type embeds: without an explicitly declared Close of its own, Server[T] promotes the embedded http.Server's zero-arg, non-graceful Close() error — a hard reset that drops in-flight connections instead of the graceful stop above. Anyone calling the old Close(ctx) convention by habit gets a compile error, not a silently different shutdown.

func (*Server[T]) Deps added in v0.22.0

func (t *Server[T]) Deps() []any

func (*Server[T]) DisableGate added in v0.25.0

func (t *Server[T]) DisableGate()

DisableGate permanently turns off gate-checking for this instance — for servers that must never be traffic-gated (e.g. ops's own readiness endpoint, which would otherwise mask its own status behind a blanket 503, and could false-fail a liveness check sharing the same listener).

Must be called before Start, synchronously by the same caller that wires this Server: initFn reads t.gate/t.gateDisabled once, while building the request pipeline, and never again — a call after Start has already run is a silent no-op.

func (*Server[T]) HealthCheck added in v0.22.0

func (t *Server[T]) HealthCheck(_ context.Context) error

func (*Server[T]) Inject added in v0.22.0

func (t *Server[T]) Inject(args []any)

func (*Server[T]) ProbeReady added in v0.24.0

func (t *Server[T]) ProbeReady(ctx context.Context) error

ProbeReady reports traffic readiness (SDI duck typing; no ops import): non-nil if Serve failed after Start (same as HealthCheck), or if a gate is wired, enabled, and not yet open — a caller relying only on HealthCheck would see this Server as ready while every real request is still answered 503 by the gate handler.

func (*Server[T]) Start added in v0.22.0

func (t *Server[T]) Start(ctx context.Context) (func(context.Context) error, error)

Jump to

Keyboard shortcuts

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