httpapi

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package httpapi serves the public HTTP API, following its contract (api/openapi.yaml): the server and its timeouts, the probes, and the middleware every request goes through (request identifier, access log, panic recovery, security headers). It never serves HTML: every error is an RFC 9457 problem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(opts Options) http.Handler

NewHandler returns the handler of the API: its routes behind the request middleware.

func NewServer

func NewServer(h http.Handler, logger *slog.Logger) *http.Server

NewServer returns a server for h with every phase of a request bounded; Serve gives it its listener. Its own errors, such as TLS handshake failures, go to logger.

func Serve

func Serve(ctx context.Context, srv *http.Server, ln net.Listener) error

Serve serves srv on ln until ctx is done, then shuts it down: it stops accepting connections and lets in-flight requests finish, for at most shutdownTimeout. It returns nil after a clean shutdown.

Types

type Options

type Options struct {
	// Ready backs /readyz.
	Ready Readiness
	// Logger receives the access log and the recovered panics.
	Logger *slog.Logger
	// NewID makes a request identifier when the client sent no valid one;
	// nil means crypto/rand.Text.
	NewID func() string
}

Options configures the handler.

type Readiness

type Readiness interface {
	// Ready reports whether every snapshot is loaded.
	Ready() bool
}

Readiness tells whether the API can answer checks.

Directories

Path Synopsis
Package contracttest checks HTTP exchanges against the public contract, api/openapi.yaml.
Package contracttest checks HTTP exchanges against the public contract, api/openapi.yaml.

Jump to

Keyboard shortcuts

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