Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, listenAddr string, router http.Handler, logger *slog.Logger, opts ...Option) error
Run creates and runs an HTTP server until ctx is canceled or startup fails.
Parameters:
- ctx controls the server lifetime; cancellation triggers graceful shutdown.
- listenAddr is passed to http.Server.Addr, for example ":8080".
- router is assigned to http.Server.Handler.
- logger is used for lifecycle logs; if nil, lifecycle logging is disabled.
- opts override default timeouts via WithOptions.
Run returns an error when startup fails (for example, address already in use) or when graceful shutdown fails.
func RunServer ¶
RunServer starts server with ListenAndServe and manages graceful shutdown.
Parameters:
- ctx controls the server lifetime; cancellation triggers graceful shutdown.
- server is the fully configured http.Server instance to run.
- logger is used for lifecycle logs; if nil, lifecycle logging is disabled.
RunServer uses the default shutdown timeout. It returns an error when startup fails or when graceful shutdown fails.
Types ¶
type Option ¶
type Option func(*Options)
Option mutates Options used by Run.
func WithOptions ¶
WithOptions overwrites the server timeout options used by Run.
type Options ¶
type Options struct {
// ReadHeaderTimeout limits how long to read request headers.
ReadHeaderTimeout time.Duration
// WriteTimeout limits the time spent writing the response.
WriteTimeout time.Duration
// IdleTimeout sets how long to keep idle connections open.
IdleTimeout time.Duration
// ShutdownTimeout bounds how long to wait for graceful shutdown.
ShutdownTimeout time.Duration
}
Options configures the HTTP server timeouts applied by Run.
Click to show internal directories.
Click to hide internal directories.