Documentation
¶
Overview ¶
Package server implements the brainjar HTTP server. It wraps a stdlib ServeMux and provides lifecycle management (listen, graceful shutdown). Routes are registered on the returned mux; middleware is assembled by the caller and wrapped via Handler() before serving.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Logger is attached to the server for informational logging. Defaults
// to slog.Default() when nil. Middleware receive their own logger
// where needed.
Logger *slog.Logger
}
Options configures a Server. Zero values select sane defaults.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the brainjar HTTP server.
func New ¶
New creates a Server bound to host:port. Callers register routes on Mux(), wrap it with middleware via Handler(), then ListenAndServe.
func NewWithOptions ¶
NewWithOptions creates a Server with explicit options.
func (*Server) Handler ¶
Handler replaces the server's HTTP handler, typically with a middleware chain wrapping Mux(). Call after routes are registered and before ListenAndServe. If never called, the mux is served directly — no middleware, no auth.
func (*Server) ListenAndServe ¶
ListenAndServe binds the listener and starts serving. It returns the resolved address (useful when port=0) and a channel that receives the first non-ErrServerClosed error from Serve, or nil on clean shutdown.
func (*Server) RegisterHealth ¶
func (s *Server) RegisterHealth()
RegisterHealth wires the /healthz endpoint. It returns 200 with a JSON body regardless of middleware — probes hit this directly. Liveness: no I/O, no dependency checks. Failing this means the process is wedged and the orchestrator should restart it.
func (*Server) RegisterReady ¶
RegisterReady wires the /readyz endpoint. It returns 200 when the process is ready to serve traffic (DB is reachable), 503 otherwise. Readiness: dependency checks live here. Failing this pulls the pod out of load balancing without restarting it — transient DB blips don't turn into restart loops.