Documentation
¶
Overview ¶
Package server provides functionality for HTTP server management.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Port string // Port on which the server will listen ReadTimeout time.Duration // Maximum duration for reading the entire request WriteTimeout time.Duration // Maximum duration before timing out writes of the response IdleTimeout time.Duration // Maximum amount of time to wait for the next request ShutdownTimeout time.Duration // Maximum time to wait for server shutdown }
Config contains server configuration parameters. It defines all the timeouts and connection settings for the HTTP server.
func NewConfig ¶
func NewConfig(port string, readTimeout, writeTimeout, idleTimeout, shutdownTimeout time.Duration) Config
NewConfig creates a new server configuration from the provided values. It initializes a Config struct with the specified parameters.
Parameters:
- port: The port on which the server will listen
- readTimeout: Maximum duration for reading the entire request
- writeTimeout: Maximum duration before timing out writes of the response
- idleTimeout: Maximum amount of time to wait for the next request
- shutdownTimeout: Maximum time to wait for server shutdown
Returns:
- A Config struct initialized with the provided values
type Server ¶
type Server struct { *http.Server // Embedded standard HTTP server // contains filtered or unexported fields }
Server represents an HTTP server with additional functionality. It extends the standard http.Server with logging, context-aware logging, and graceful shutdown capabilities.
func New ¶
func New(cfg Config, handler http.Handler, logger *zap.Logger, contextLogger *logging.ContextLogger) *Server
New creates a new server with the given configuration and handler. It applies middleware to the handler and initializes the HTTP server.
Parameters:
- cfg: Server configuration parameters
- handler: HTTP handler for processing requests
- logger: Logger for server events
- contextLogger: Context-aware logger for request-scoped logging
Returns:
- A pointer to a new Server instance
func (*Server) Shutdown ¶
Shutdown gracefully shuts down the server. It stops accepting new connections and waits for existing connections to complete processing, up to the configured shutdown timeout.
Parameters:
- ctx: Context for the shutdown operation, which may be cancelled
Returns:
- An error if the shutdown fails, or nil on success