Documentation
¶
Overview ¶
Package httpserver implements helper functions for creating http servers.
Index ¶
Constants ¶
View Source
const ( DefayltPort = 8000 //nolint:revive DefaultLivenessProbePath = "/alive" DefaultReadHeaderTimeout = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a http server that implements common requirements such as liveness probe, exposing metrics and graceful shutdown
func NewServer ¶
func NewServer(config ServerConfig) *Server
NewServer creates a new http server with the given configuration.
type ServerConfig ¶
type ServerConfig struct { // Logger is the logger used by the server Logger *slog.Logger // Port is the port the server listens on. Default to DefaultPort Port int // EnableMetrics enables the prometheus metrics handler at the /metrics route EnableMetrics bool // LivenessProbe enables the liveness probe handler LivenessProbe bool // LivenessProbePath is the path for the liveness probe handler. Default is DefaultLivenessProbePath LivenessProbePath string // ReadHeaderTimeout is the maximum duration before timing out read of the request headers. // Defaults to DefaultReadHeaderTimeout ReadHeaderTimeout time.Duration }
ServerConfig holds the configuration for the http server
Click to show internal directories.
Click to hide internal directories.