Documentation
¶
Overview ¶
Package server provides a production-ready HTTP server with graceful shutdown, signal handling, and lifecycle hooks.
Index ¶
- type Option
- func WithAddr(addr string) Option
- func WithIdleTimeout(d time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithReadTimeout(d time.Duration) Option
- func WithShutdownTimeout(d time.Duration) Option
- func WithTLS(certFile, keyFile string) Option
- func WithWriteTimeout(d time.Duration) Option
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Server)
Option configures a Server.
func WithIdleTimeout ¶
WithIdleTimeout sets the idle timeout (default 120s).
func WithLogger ¶
WithLogger sets the structured logger (default slog.Default()).
func WithReadTimeout ¶
WithReadTimeout sets the read timeout (default 15s).
func WithShutdownTimeout ¶
WithShutdownTimeout sets the graceful shutdown timeout (default 30s).
func WithWriteTimeout ¶
WithWriteTimeout sets the write timeout (default 60s).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps http.Server with graceful shutdown and lifecycle hooks.
func (*Server) Addr ¶ added in v0.5.0
Addr returns the listener address after the server has started. Returns nil if the server has not started yet.
func (*Server) OnShutdown ¶
OnShutdown registers a hook that runs after HTTP connections are drained. Errors are logged but all hooks still execute.
func (*Server) OnStart ¶
OnStart registers a hook that runs before the server starts listening. If any hook returns an error, Start aborts and returns the error.