server

package
v0.0.0-...-ac1c1c5 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 8 Imported by: 14

Documentation

Index

Constants

View Source
const LogHandlerKey string = "Log"
View Source
const RequestIDHandlerKey string = "RequestID"

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	http.Server
	Middleware             map[string]alice.Constructor
	MiddlewareOrder        []string
	Alice                  *alice.Chain
	CertFile               string
	KeyFile                string
	DefaultShutdownTimeout time.Duration
	HandleOSSignals        bool
}

Server is a http.Server with sensible defaults, which supports configurable middleware and timeouts, and shuts down cleanly on SIGINT/SIGTERM

func New

func New(bindAddr string, router http.Handler) *Server

New creates a new server

func (*Server) Close

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

Close is simply a wrapper around Shutdown that enables Server to be treated as a Closable

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe sets up SIGINT/SIGTERM signals, builds the middleware chain, and creates/starts a http.Server instance

If CertFile/KeyFile are both set, the http.Server instance is started using ListenAndServeTLS. Otherwise ListenAndServe is used.

Specifying one of CertFile/KeyFile without the other will panic.

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(certFile, keyFile string) error

ListenAndServeTLS sets KeyFile and CertFile, then calls ListenAndServe

func (*Server) Shutdown

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

Shutdown will gracefully shutdown the server, using a default shutdown timeout if a context is not provided.

Jump to

Keyboard shortcuts

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