httpserver

package
v0.5.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

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.

func (*Server) Handle

func (s *Server) Handle(pattern string, handler http.Handler)

Handle registers the handler for the given pattern.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the http server and listens for incoming requests. It also listens for os signals to gracefully shutdown the server.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL