Documentation
¶
Overview ¶
Package server is the HTTP server of the service and its graceful stop.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrShutdown = errors.New("server: graceful shutdown")
ErrShutdown marks a stop that failed other than by running out of time: what Run returns then is a failure of the shutdown, not of serving.
Functions ¶
func Routes ¶
Routes is the service's handler: the health check, and whatever mount puts on the mux — the methods of the contract, by the Connect server (R33). A panic in any of them is answered here, and CORS is answered to appOrigin, when it is set, on every path and every answer.
The router is the standard library's: a Connect handler is an http.Handler, and a pattern with a method is all the routes need.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP server and its graceful stop.
func (*Server) Addr ¶
Addr is the address the server is bound to, empty before Listen. It is safe to call while the server is starting or serving.
func (*Server) Listen ¶
Listen binds the port without serving on it yet. Run binds it itself when nothing did, but the process calls Listen first: binding early is how a port that is already taken is reported as a failed start, before the service says it has started, rather than swallowed by the goroutine inside Run.
func (*Server) Run ¶
Run serves until ctx is cancelled, then stops gracefully. The stop is driven by the context rather than by a signal handler of its own, so that every part of the process stops for the same reason at the same moment.
A request still being handled when the drain's share of the way out is spent is cut off rather than waited for, and that is still the stop that was asked for: the line saying so is a warning, and Run returns no error. A failure is what nobody asked for — a server that stopped serving on its own.