Documentation
¶
Overview ¶
Package httpserver serves every HTTP route group, such as the codec server, on one port separate from the gateway's.
A route group contributes its handlers as Route values through AsRoutes, and owns everything specific to its callers, including CORS and authentication. This package owns only the listener: its address, TLS, and lifecycle. With no group enabled, nothing binds.
A Server is single-use and is not restartable after Server.Stop.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Module provides the HTTP server and forces its construction, since nothing else depends on it. Include it unconditionally: with no routes contributed, it yields a nil Server and no lifecycle hook, so the module is inert.
Functions ¶
Types ¶
type Params ¶
type Params struct {
fx.In
Shutdowner fx.Shutdowner
Config *config.Config
Logger logger.Logger
Lifecycle fx.Lifecycle
Routes []Route `group:"http_routes"`
}
Params collects the fx-provided dependencies the HTTP server needs. Routes holds whatever the enabled route groups contributed, and may be empty.
type Route ¶
Route mounts one route group's handler on the shared mux at Pattern, an http.ServeMux pattern. Patterns from different groups must not overlap, or building the server panics.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the HTTP route groups on one port, separate from the gateway's.
func New ¶
func New( hostPort string, h http.Handler, tlsCfg *tls.Config, log logger.Logger, abort func(error), ) *Server
New returns a Server that serves h on hostPort. It binds nothing, Server.Start does that.
func (*Server) Addr ¶
Addr is the address the server is accepting on, including the port chosen for a port-zero hostPort, or nil before Server.Start returns successfully. Safe for concurrent use.
func (*Server) Start ¶
Start binds the listener and serves in a background goroutine until Server.Stop, returning once the listener is accepting. It returns an error only if the bind fails; a serving failure after that reaches the abort function given to New instead.
Call it at most once. A Server is not restartable after Server.Stop.