server

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: AGPL-3.0 Imports: 17 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 DepTracker added in v0.5.12

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

DepTracker records the outcome of calls to out-of-process dependencies (embedder, LLM) so verbose healthz can report them without those packages depending on server. Call sites feed it via Record; nothing here changes /readyz, which stays store-only.

Lives in internal/server (rather than a new package) because the only consumer of the read side is the health handler here, and the only producers (cmd/memini's embed/llm decorators) already import server for Server/SetReady — a dedicated internal/depstatus package would just add an import hop without decoupling anything.

func NewDepTracker added in v0.5.12

func NewDepTracker() *DepTracker

NewDepTracker returns an empty tracker.

func (*DepTracker) Record added in v0.5.12

func (t *DepTracker) Record(dep string, err error)

Record logs the outcome of one call to dep (e.g. "embedder", "llm"). A nil err records success, advancing lastSuccess; a non-nil err records the error text and its timestamp. Either way the other field is left as-is, so a dependency that is failing now but succeeded five minutes ago still reports that last success.

type Options

type Options struct {
	Addr            string
	ShutdownTimeout time.Duration
	// APIKey, when non-empty, gates /metrics on the main port behind the same
	// bearer token used by the /v1 routes. A dedicated MetricsAddr port is
	// unauthenticated instead.
	APIKey string
	// MetricsAddr, when set and distinct from Addr, serves /metrics on its own
	// unauthenticated listener instead of the main router — a port meant to stay
	// in-cluster (keep it off any public route).
	MetricsAddr string
	// UIAddr, when set and distinct from Addr, serves the admin UI on its own
	// listener instead of the main router (see MountUI). The shell embeds the
	// API key, so isolating it keeps that key off the main port — expose UIAddr
	// only on a trusted (LAN) gateway.
	UIAddr 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) MountUI added in v0.5.10

func (s *Server) MountUI(spa http.Handler)

MountUI arranges for the SPA handler to be served. When UIAddr is set and distinct from Addr, spa is served ONLY on that dedicated listener, which delegates requests matching an API route to the main router so the same-origin SPA can still call /v1 — keeping the token-embedding shell off the main port. Otherwise spa is mounted as a catch-all on the main router, serving it on the main port (single-listener default).

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) SetDeps added in v0.5.12

func (s *Server) SetDeps(t *DepTracker)

SetDeps installs the dependency tracker rendered by GET /healthz?verbose=1. Unset (nil) is fine: the verbose handler renders ok defaults for every dep.

func (*Server) SetLLMConfigured added in v0.5.12

func (s *Server) SetLLMConfigured(v bool)

SetLLMConfigured records whether the LLM pipeline is configured, for the "llm.configured" field in verbose healthz.

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