server

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-3-Clause Imports: 24 Imported by: 1

Documentation

Overview

Package server is an extremely opinionated package for gluing together HTTP servers, managing their listeners, TLS certificates, domains, metrics and data dumps.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultIdleTimeout  = 30 * time.Minute
	DefaultReadTimeout  = 1 * time.Minute
	DefaultWriteTimeout = 1 * time.Minute
)

Default values for HTTP server timeouts.

Functions

This section is empty.

Types

type HTTPOptions

type HTTPOptions struct {
	Handlers     Handlers
	Name         string
	Listen       string
	ListenTLS    string
	TLSCerts     []TLSCert
	IdleTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

HTTPOptions holds parameters for WithHTTP method. If timeouts are not set, package Default values will be used.

func (*HTTPOptions) SetHandler

func (o *HTTPOptions) SetHandler(h http.Handler, domains ...string)

SetHandler sets an HTTP handler to serve specific domains.

type Handlers

type Handlers map[string]http.Handler

Handlers maps HTTP handlers to domains.

func NewHandlers

func NewHandlers() (h Handlers)

NewHandlers constructs new instance of Handlers.

func (Handlers) Set

func (dh Handlers) Set(h http.Handler, domains ...string) Handlers

Set sets an HTTP handler to serve specific domains. If domain list is empty, this handler will be used as Default one.

type Options

type Options struct {
	Name                        string
	Version                     string
	BuildInfo                   string
	ListenInstrumentation       string
	ListenInstrumentationTLS    string
	InstrumentationTLSCert      string
	InstrumentationTLSKey       string
	ACMECertsDir                string
	ACMECertsEmail              string
	SetupInstrumentationRouters func(base, api *http.ServeMux)

	Logger *slog.Logger

	EmailService       *email.Service
	RecoveryService    *recovery.Service
	MaintenanceService *maintenance.Service
}

Options structure contains optional properties for the Server.

type Server

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

Server contains all required properties, services and functions to provide core functionality.

func New

func New(o Options) (s *Server, err error)

New initializes new server with provided options.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts servers.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown gracefully terminates servers.

func (*Server) Version

func (s *Server) Version() (v string)

Version returns server version with build info data suffixed if exists.

func (*Server) WithDataDumpService

func (s *Server) WithDataDumpService(name string, service datadump.Interface)

WithDataDumpService adds a service with data dump interface to be used on instrumentation handler /data request.

func (*Server) WithHTTP

func (s *Server) WithHTTP(o HTTPOptions) (err error)

WithHTTP add an HTTP server with a specific name, that listens for plain http or encrypted connections to the list of servers.

func (*Server) WithMetrics

func (s *Server) WithMetrics(cs ...prometheus.Collector)

WithMetrics registers prometheus collector to be exposed on instrumentation handler /metrics request.

type TLSCert

type TLSCert struct {
	Cert string
	Key  string
}

TLSCert holds filesystem paths to TLS certificate and its key.

Jump to

Keyboard shortcuts

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