Documentation
¶
Overview ¶
Package server holds the generated server wiring (Serve) and the functional options consumers use to register their business-logic ServerInterface implementation plus auth, WebAuthn-store, and HSM/KMS signer overrides. The cmd/server entrypoint is a thin wrapper around Serve; downstream services import this package directly:
server.Serve(ctx,
server.WithImpl(myHandlers{}), // business logic
server.WithAuthJWT(myVerifier), // e.g. RS256 / JWKS
server.WithGetCertificate(hsmGetCert), // HSM-backed TLS
server.WithAuthMTLS(myCACVerifier), // CAC/PIV issuer policy
)
Index ¶
- func Serve(ctx context.Context, opts ...Option) error
- type Option
- func WithAuthAPIKey(fn func(*http.Request) error) Option
- func WithAuthJWT(fn func(*http.Request) error) Option
- func WithAuthMTLS(fn func(*http.Request, securex.MTLSPolicy) error) Option
- func WithExtraRoutes(fn func(mux *http.ServeMux)) Option
- func WithGetCertificate(fn func(*tls.ClientHelloInfo) (*tls.Certificate, error)) Option
- func WithImpl(impl apic.ServerInterface) Option
- func WithInsecureHTTP() Option
- func WithLogger(l *slog.Logger) Option
- func WithMCPImpl(impl genmcp.MCPServerInterface) Option
- func WithMetrics(m obsx.MetricsProvider) Option
- func WithMiddleware(mw ...func(http.Handler) http.Handler) Option
- func WithTelemetry(tp *obsx.TelemetryProvider) Option
- func WithWSImpl(impl genws.WSServerInterface) Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Options)
Option mutates Options.
func WithAuthAPIKey ¶
WithAuthAPIKey overrides the default API-key (HMAC) verifier.
func WithAuthJWT ¶
WithAuthJWT overrides the default HS256 JWT verifier (e.g. RS256/JWKS).
func WithAuthMTLS ¶
WithAuthMTLS wires the mTLS issuer-label verifier (PIV/CAC/custom).
func WithExtraRoutes ¶
WithExtraRoutes registers application-specific routes on the server mux after the generated API/WS routes (see Options.ExtraRoutes). Each handler must enforce its own auth; patterns must not collide with generated routes.
func WithGetCertificate ¶
func WithGetCertificate(fn func(*tls.ClientHelloInfo) (*tls.Certificate, error)) Option
WithGetCertificate wires an HSM/KMS-backed TLS certificate source.
func WithImpl ¶
func WithImpl(impl apic.ServerInterface) Option
WithImpl registers the business-logic implementation of the generated HTTP ServerInterface.
func WithInsecureHTTP ¶
func WithInsecureHTTP() Option
WithInsecureHTTP opts the listener out of TLS and serves plain HTTP for deployments that terminate TLS upstream (ingress/mesh). It is the code-level equivalent of the config opt-in server.tls.mode:"off". This disables transport encryption on the listener — only use it when a trusted upstream (ingress controller, service mesh sidecar) terminates TLS and the process hop is on a trusted network. Without this option (or the config opt-in) Serve refuses to boot unless a TLS cert is configured.
func WithLogger ¶
WithLogger configures a custom slog logger.
func WithMCPImpl ¶
func WithMCPImpl(impl genmcp.MCPServerInterface) Option
WithMCPImpl registers the business-logic implementation of the generated MCP tool interface. When not supplied, genmcp.UnimplementedMCPServer{} is used (returns ErrNotImplemented for every tool). Register is always called so per-tool rate limits and RBAC (SetToolBuckets / SetToolRoles) are installed regardless of which impl is wired.
func WithMetrics ¶
func WithMetrics(m obsx.MetricsProvider) Option
WithMetrics configures a custom metrics provider.
func WithMiddleware ¶
WithMiddleware appends user middleware (runs after auth, rate limiting, CORS, and logging).
func WithTelemetry ¶
func WithTelemetry(tp *obsx.TelemetryProvider) Option
WithTelemetry configures OpenTelemetry tracing/metrics.
func WithWSImpl ¶
func WithWSImpl(impl genws.WSServerInterface) Option
WithWSImpl registers the business-logic implementation of the generated WebSocket interface.
type Options ¶
type Options struct {
Logger *slog.Logger
Middleware []func(http.Handler) http.Handler
Metrics obsx.MetricsProvider
Telemetry *obsx.TelemetryProvider
// Impl is the business-logic implementation of the generated HTTP
// ServerInterface. Embed apic.UnimplementedServer and override only
// the methods you need. Nil uses apic.UnimplementedServer{}.
Impl apic.ServerInterface
// WSImpl is the business-logic implementation of the generated
// WebSocket interface. Nil uses genws.UnimplementedWSServer{}.
WSImpl genws.WSServerInterface
// MCPImpl is the business-logic implementation of the generated MCP
// tool interface. Embed genmcp.UnimplementedMCPServer and override only
// the tools you implement. Nil uses genmcp.UnimplementedMCPServer{}.
// Register is called unconditionally on startup so SetToolBuckets and
// SetToolRoles (per-tool rate limits and RBAC) are always installed.
MCPImpl genmcp.MCPServerInterface
// AuthAPIKey / AuthJWT override the default credential verifiers. Use
// AuthJWT to swap the built-in HS256 gate for RS256/ES256/JWKS or an
// OIDC introspection call (e.g. an HSM-signed RS256 token verified
// against the signer's public key). Nil keeps the built-in gate.
AuthAPIKey func(*http.Request) error
AuthJWT func(*http.Request) error
// AuthMTLS enforces deployment-specific mTLS issuer-label policy
// (PIV/CAC/custom) AFTER securex.VerifyMTLS accepts the request. When
// the spec declares any mtls route with supported_issuers, Serve
// refuses to start unless this is wired; IssuerCNVerifier is a ready
// default the thin entrypoint installs.
AuthMTLS func(*http.Request, securex.MTLSPolicy) error
// GetCertificate, when set, supplies the TLS server certificate at
// handshake time instead of loading a PEM keypair from disk. Wire it
// to signerx.GetCertificateForServer so the private key lives in an
// HSM/KMS and never enters the process as raw bytes (NIST SC-12).
GetCertificate func(*tls.ClientHelloInfo) (*tls.Certificate, error)
// ExtraRoutes registers application-specific HTTP routes on the SAME mux
// as the generated API, after the generated routes are registered. Use it
// for bespoke endpoints that are not part of the apic spec — webhooks
// with signature auth, reverse proxies, or a hand-wired sub-API — so a
// service can adopt server.Serve without forking it. These routes share
// the generated httpx pipeline (body limits, security headers, CORS,
// per-IP rate limit) but are NOT covered by the generated per-route auth:
// each handler MUST enforce its own authentication. Patterns must not
// collide with a generated route (http.ServeMux panics on duplicates).
ExtraRoutes func(mux *http.ServeMux)
// InsecureHTTP opts the listener OUT of TLS and serves plain HTTP. It
// exists for deployments that terminate TLS upstream (ingress/mesh) and
// hand the process plaintext on a trusted network hop. This is the
// code-level equivalent of the config opt-in server.tls.mode:"off";
// either one enables it. It is OFF by default and must be set
// explicitly — with neither opt-in set, Serve still refuses to boot
// without a TLS cert, so plaintext is never served by accident. When
// enabled, Serve logs a one-time warning; terminate TLS upstream.
InsecureHTTP bool
}
Options configures the generated server. The zero value is valid: it serves the generated UnimplementedServer (501 for un-overridden routes; working WebAuthn ceremonies), the built-in HS256 JWT / HMAC API-key gates, and a PEM-loaded TLS certificate. Override any concern via the With* functions.