httpserver

package
v0.0.0-...-85df02f Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package httpserver runs an HTTP service with the probes, metrics, tracing, request logging and graceful shutdown every LabFlow service needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Probe

func Probe(ctx context.Context, addr string) error

Probe calls the readiness endpoint on addr; container health checks use it because distroless images have no shell or curl.

Types

type Check

type Check func(context.Context) error

Check reports whether a dependency the service needs is available.

type Config

type Config struct {
	Addr string
	// ShutdownDelay keeps serving, with readiness failing, so load balancers
	// stop routing before connections drain.
	ShutdownDelay   time.Duration
	ShutdownTimeout time.Duration
	// Public marks an internet-facing service: an inbound traceparent becomes
	// a span link instead of the parent, so clients cannot choose trace IDs.
	Public bool
}

Config holds the listener and shutdown settings.

func ConfigFromEnv

func ConfigFromEnv(e *config.Env) Config

ConfigFromEnv reads HTTP_ADDR, SHUTDOWN_DELAY and SHUTDOWN_TIMEOUT.

type Server

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

Server serves app behind /healthz, /readyz and /metrics.

func New

func New(cfg Config, log *slog.Logger, routes *http.ServeMux, checks ...Check) *Server

New builds a server around the service's routes. Requests other than the probes are traced, measured and logged with their route pattern; unknown routes and methods answer with problem details; a panic becomes a 500.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run serves until ctx is cancelled, then fails readiness, waits ShutdownDelay and drains in-flight requests within ShutdownTimeout.

Jump to

Keyboard shortcuts

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