Documentation
¶
Overview ¶
Package httpserver builds the HTTP transport every service in this repo runs on: CORS, access logging with correlation IDs, and the Serve/Shutdown lifecycle pkg/boot.Service expects. A service package supplies only its own routes and gets the rest for free instead of rebuilding http.Server and its middleware chain by hand.
One Server hosts any number of Registrations on one mux behind one CORS and access-logging layer; http.ServeMux precedence decides which route a request gets, and panics at boot on a pattern two of them claim.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Name string
Component string
Address string
CORS config.CORSConfig
Timeouts config.HTTPDefaults
// Registrations are the hosted services: one for a standalone binary.
Registrations []Registration
}
Config is what pkg/boot.Boot builds from Registrations plus what only the platform layer decides: name, listen address, and the CORS/timeout defaults every HTTP server in this repo shares.
type Registration ¶
type Registration struct {
// ServiceTokenHeader, if set, is added to CORS's allowed headers so a
// browser-based service-to-service caller can present it; leave empty
// if the service takes no service-token header.
ServiceTokenHeader string
// SetupRoutes registers the service's handlers on mux. Required.
SetupRoutes func(mux *http.ServeMux)
// Closers are closed, in order, after the HTTP server has shut down.
Closers []io.Closer
}
Registration is what a service provides: its routes, never the transport around them.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func New ¶
New builds a Server hosting cfg.Registrations. Like http.ServeMux it panics on programmer error: an empty registration list, or a pattern two registrations both claim.