httpserver

package
v0.0.0-...-9933dd3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHandlerIsNotSet           = errors.New("HTTP handler cannot be left unset")
	ErrLoggerIsNotSet            = errors.New("logger cannot be left unset")
	ErrReadHeaderTimeoutTooSmall = errors.New("read header timeout is too small")
	ErrReadTimeoutTooSmall       = errors.New("read timeout is too small")
	ErrShutdownTimeoutTooSmall   = errors.New("shutdown timeout is too small")
)

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Info(msg string)
	Warn(msg string)
	Error(msg string)
}

Logger is the logger interface accepted by the HTTP server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an HTTP server implementation, which uses the HTTP handler provided.

func New

func New(settings Settings) (s *Server, err error)

New creates a new HTTP server with the given settings. It returns an error if one of the settings is not valid.

func (*Server) GetAddress

func (s *Server) GetAddress() (address string)

GetAddress obtains the address the HTTP server is listening on.

func (*Server) Run

func (s *Server) Run(ctx context.Context, ready chan<- struct{}, done chan<- struct{})

Run runs the HTTP server until ctx is canceled. The done channel has an error written to when the HTTP server is terminated, and can be nil or not nil.

type Settings

type Settings struct {
	// Address is the server listening address.
	// It defaults to :8000.
	Address string
	// Handler is the HTTP Handler to use.
	// It must be set and cannot be left to nil.
	Handler http.Handler
	// Logger is the logger to use.
	// It must be set and cannot be left to nil.
	Logger Logger
	// ReadHeaderTimeout is the HTTP header read timeout duration
	// of the HTTP server. It defaults to 3 seconds if left unset.
	ReadHeaderTimeout time.Duration
	// ReadTimeout is the HTTP read timeout duration
	// of the HTTP server. It defaults to 3 seconds if left unset.
	ReadTimeout time.Duration
	// ShutdownTimeout is the shutdown timeout duration
	// of the HTTP server. It defaults to 3 seconds if left unset.
	ShutdownTimeout time.Duration
}

func (Settings) Copy

func (s Settings) Copy() Settings

func (*Settings) OverrideWith

func (s *Settings) OverrideWith(other Settings)

func (*Settings) SetDefaults

func (s *Settings) SetDefaults()

func (Settings) String

func (s Settings) String() string

func (Settings) ToLinesNode

func (s Settings) ToLinesNode() (node *gotree.Node)

func (Settings) Validate

func (s Settings) Validate() (err error)

Jump to

Keyboard shortcuts

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