server

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Host is a default bind address for HTTP servers
	Host string = "localhost"
	// SSL is a default configuration for HTTP servers
	SSL *SSLConfig
	// MaxConn is a default configuration for maximum connections
	MaxConn int
	// Default logger
	Logger *slog.Logger = slog.Default()
)

Functions

func FetchUID added in v1.4.0

func FetchUID(r *http.Request) (string, error)

FetchUID safely extracts uid from `X-Request-ID` header or generates a new one

func HealthHandler added in v1.0.1

func HealthHandler(w http.ResponseWriter, _ *http.Request)

HealthHandler always reponds with 200 status

func WriteCORSHeaders added in v1.4.4

func WriteCORSHeaders(w http.ResponseWriter, r *http.Request, origins []string)

Types

type DefaultHeadersExtractor added in v1.4.0

type DefaultHeadersExtractor struct {
	Headers []string
	Cookies []string
}

func (*DefaultHeadersExtractor) FromRequest added in v1.4.0

func (h *DefaultHeadersExtractor) FromRequest(r *http.Request) map[string]string

type HTTPServer

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

HTTPServer is wrapper over http.Server

func ForPort added in v1.0.1

func ForPort(port string) (*HTTPServer, error)

ForPort creates new or returns the existing server for the specified port

func NewServer

func NewServer(host string, port string, ssl *SSLConfig, maxConn int) (*HTTPServer, error)

NewServer builds HTTPServer from config params

func (*HTTPServer) Address

func (s *HTTPServer) Address() string

Address returns server scheme://host:port

func (*HTTPServer) Running added in v1.0.1

func (s *HTTPServer) Running() bool

Running returns true if server has been started

func (*HTTPServer) SetupHandler added in v1.3.0

func (s *HTTPServer) SetupHandler(path string, handler http.Handler)

SetupHandler adds new handler to mux

func (*HTTPServer) Shutdown added in v1.1.0

func (s *HTTPServer) Shutdown(ctx context.Context) error

Shutdown shuts down server gracefully.

func (*HTTPServer) ShutdownCtx added in v1.4.4

func (s *HTTPServer) ShutdownCtx() context.Context

ShutdownCtx returns context for graceful shutdown. It must be used by HTTP handlers to termniates long-running requests (SSE, long-polling).

func (*HTTPServer) Start

func (s *HTTPServer) Start() error

Start server

func (*HTTPServer) StartAndAnnounce added in v1.0.1

func (s *HTTPServer) StartAndAnnounce(name string) error

StartAndAnnounce prints server info and starts server

func (*HTTPServer) Stopped

func (s *HTTPServer) Stopped() bool

Stopped return true iff server has been stopped by user

type HeadersExtractor added in v1.4.0

type HeadersExtractor interface {
	FromRequest(r *http.Request) map[string]string
}

type RequestInfo added in v1.4.0

type RequestInfo struct {
	UID     string
	URL     string
	Headers *map[string]string
	// contains filtered or unexported fields
}

func NewRequestInfo added in v1.4.0

func NewRequestInfo(r *http.Request, extractor HeadersExtractor) (*RequestInfo, error)

func (*RequestInfo) AnyCableHeader added in v1.4.3

func (i *RequestInfo) AnyCableHeader(key string) string

func (*RequestInfo) Param added in v1.4.3

func (i *RequestInfo) Param(key string) string

type SSLConfig added in v1.0.1

type SSLConfig struct {
	CertPath string
	KeyPath  string
}

SSLConfig contains SSL parameters

func NewSSLConfig added in v1.0.1

func NewSSLConfig() SSLConfig

NewSSLConfig build a new SSLConfig struct

func (*SSLConfig) Available added in v1.0.1

func (opts *SSLConfig) Available() bool

Available returns true iff certificate and private keys are set

Jump to

Keyboard shortcuts

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