server

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package server wires the HTTP surface: middleware, health probes, metrics, graceful shutdown, and a chi router that other packages mount routes onto.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Addr            string
	ShutdownTimeout time.Duration
	// APIKey, when non-empty, gates /metrics behind the same bearer token used
	// by the /v1 routes.
	APIKey string
}

Options configures the server without importing the config package.

type ReadinessFunc

type ReadinessFunc func(context.Context) error

ReadinessFunc reports whether the service is ready to serve traffic. A nil error means ready; a non-nil error is surfaced on /readyz.

type Server

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

Server owns the HTTP server and its router.

func New

func New(opts Options, log *slog.Logger, reg *prometheus.Registry) *Server

New builds a Server with base middleware, /healthz, /readyz and /metrics. Additional routes are mounted via Router before calling Run.

func (*Server) Router

func (s *Server) Router() chi.Router

Router exposes the underlying router so other packages can mount routes.

func (*Server) Run

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

Run starts the HTTP server and blocks until ctx is cancelled, then performs a graceful shutdown bounded by the configured timeout.

func (*Server) SetReady

func (s *Server) SetReady(fn ReadinessFunc)

SetReady installs the readiness check used by /readyz.

Jump to

Keyboard shortcuts

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