Documentation
¶
Overview ¶
Package httpserver is the public HTTP server component: a net/http Server with sane timeouts over a Go 1.22+ ServeMux, health probes on the public port, and 404/405 rendered as the standard error envelope.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler wraps mux so unmatched requests render the error envelope instead of net/http's plain-text 404 and 405. Matched requests go straight to the mux.
Types ¶
type Config ¶
type Config struct {
Addr string
ReadHeaderTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
}
Config is the server's listen address and timeouts.
type Option ¶
type Option func(*Server)
Option configures the Server.
func WithOnShutdown ¶ added in v0.2.2
func WithOnShutdown(f func()) Option
WithOnShutdown runs f when Stop begins, before in-flight requests drain. Use it to end responses that never finish on their own, such as streams, which http.Server.Shutdown would otherwise wait on for the whole deadline.
type SPAConfig ¶
type SPAConfig struct {
// FS holds the built application: index.html at the root next to its
// assets (the output directory of Vite, esbuild or webpack).
FS fs.FS
// ServerPrefixes are paths the server owns ("/api/", "/webhooks/"): a
// request under one that matches no route is a 404 error, never the
// shell.
ServerPrefixes []string
// Immutable lists the path prefixes whose files are content-hashed and
// can be cached forever. Default: "/assets/", where Vite and most
// bundlers put them. Everything else revalidates.
Immutable []string
// Head returns HTML inserted before </head> of the shell on every
// request: meta tags carrying per-request values such as a CSRF token,
// the locale or public configuration. It must escape what it prints.
Head func(r *http.Request) string
}
SPAConfig describes a single-page application served by the same process as its API.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a lifecycle Component and Runner around http.Server.