server

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPkg a common package error.
	ErrPkg = errors.New("server")
	// ErrServerUnableListenAndServe server error.
	ErrServerUnableListenAndServe = fmt.Errorf("%w: server unable to listen and serve", ErrPkg)
	// ErrServerCertificateDoesNotExist error.
	ErrServerCertificateDoesNotExist = fmt.Errorf("%w: certificate file does not exist", ErrPkg)
	// ErrServerKeyDoesNotExist error.
	ErrServerKeyDoesNotExist = fmt.Errorf("%w: key file does not exist", ErrPkg)
	// ErrServerUnableToMarshal error.
	ErrServerUnableToMarshal = fmt.Errorf("%w: unable to marshal", ErrPkg)
	// ErrServerShutdownFailure error.
	ErrServerShutdownFailure = fmt.Errorf("%w: unable to shutdown", ErrPkg)
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Port             int           `env:"PORT,default=8080"              json:"port"`
	ReadTimeout      time.Duration `env:"READ_TIMEOUT,default=30s"       json:"readTimeout"`
	WriteTimeout     time.Duration `env:"WRITE_TIMEOUT,default=30s"      json:"writeTimeout"`
	ErrorsBufferSize int           `env:"ERRORS_BUFFER_SIZE,default=100" json:"errorsBufferSize"`
	TLS              *TLS          `env:"TLS,prefix=TLS_"                json:"tls"`
}

Config is a struct containing server configuration values.

type DefaultServer

type DefaultServer struct {
	http.Server
	// contains filtered or unexported fields
}

DefaultServer is a web server.

func New

func New(options ...Option) *DefaultServer

New a factory function to create a new server.

func (*DefaultServer) Done

func (s *DefaultServer) Done()

Done blocks until the server is fully stopped.

func (*DefaultServer) Errors

func (s *DefaultServer) Errors() <-chan error

Errors subscribe to async errors.

func (*DefaultServer) Start

func (s *DefaultServer) Start()

Start method to start a web server.

func (*DefaultServer) Stop

func (s *DefaultServer) Stop(ctx context.Context, timeout time.Duration)

Stop method to stop a web server.

type Handler

type Handler interface {
	http.Handler
}

Handler http handler.

type LogFunc

type LogFunc func(message string)

LogFunc to allow log warnings and infos.

type Option

type Option func(p *DefaultServer)

Option function.

func WithConfig

func WithConfig(config *Config) Option

WithConfig configuration option.

func WithHandler

func WithHandler(handler http.Handler) Option

WithHandler configuration option.

func WithLogFunc

func WithLogFunc(fn LogFunc) Option

WithLogFunc configuration option.

func WithShutdownFunc

func WithShutdownFunc(function func()) Option

WithShutdownFunc configuration option.

type Server

type Server interface {
	Start()
	Stop(ctx context.Context, timeout time.Duration)
	Done()
	Errors() <-chan error
}

Server http server.

type TLS

type TLS struct {
	Cert   string `env:"CERT"    json:"cert"`
	Key    string `env:"KEY"     json:"key"`
	CACert string `env:"CA_CERT" json:"caCert"`
}

TLS secure connection configuration.

Jump to

Keyboard shortcuts

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