Documentation
¶
Overview ¶
Package httpserver provides a small HTTP server with context-driven graceful-shutdown lifecycle management.
It owns the start/stop machinery — listen, context-cancellation shutdown, and the start/shutdown error contract — and nothing else: the caller supplies the http.Handler and wires the cancellation (typically via signal.NotifyContext), passing the resulting context to Serve. It holds no CLI or orchestration logic and is reusable by any service that needs to serve HTTP and stop cleanly.
Index ¶
Constants ¶
const ( // ErrServerStart indicates the server could not start listening. ErrServerStart errs.Const = "failed to start server" // ErrServerShutdown indicates the server did not shut down within the deadline. ErrServerShutdown errs.Const = "failed to shutdown server" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps an *http.Server with lifecycle management. It is a value type: the non-copyable server machinery lives behind the http pointer field, so copies share the same underlying server.
func (Server) Serve ¶
Serve starts the server and blocks until ctx is cancelled or startup fails, then shuts down gracefully within timeout. Request contexts derive from ctx (via http.Server.BaseContext), so they observe the same lifecycle cancellation. When ctx is cancelled, a pending startup failure is preferred over reporting a clean shutdown, so a real error is never masked.