http

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2019 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name             string                                                             // Name of the HTTP Server
	Address          string                                                             // Address on which the server will be accessible
	Port             int                                                                // Port on which the server will be accessible
	TLSEnabled       bool                                                               // Whether or not traffic should be served via HTTPS
	TLSCrtPath       string                                                             // Location of TLS Certificate
	TLSKeyPath       string                                                             // Location of TLS Key
	ReadTimeout      int                                                                // The Read Timeout for Server Requests
	WriteTimeout     int                                                                // The Write Timeout for Server Requests
	HealthHandler    bool                                                               // If true, register a healthcheck endpoint at /health
	MetricsHandler   bool                                                               // If true, register a Prometheus metrics endpoint at /metrics
	PprofHandler     bool                                                               // If true, register pprof endpoints under /debug/pprof
	PreStart         func(ctx context.Context, router *mux.Router, server *http.Server) // A function to be called before starting the web server
	PostShutdown     func(ctx context.Context)                                          // A function to be called before stopping the web server
	RegisterHandlers func(*mux.Router)                                                  // Handler registration callback function. Register your routes in this function.
	Middleware       []mux.MiddlewareFunc                                               // A list of global middleware functions to be called. Order is honored.
	CancelSignals    []os.Signal                                                        // OS Signals to be used to cancel running servers. Defaults to SIGINT/`os.Interrupt`.
}

Config contains the configuration necessary for running an HTTP/HTTPS Server.

func NewDefaultConfig

func NewDefaultConfig(name string) Config

NewDefaultConfig returns a standard configuration given a server name. It is recommended to invoke this function for a Config before providing further customization.

func (Config) NewServer

func (c Config) NewServer() Server

NewServer uses the given http Config to create and return a server ready to be run. Note that this method prepends writer.StatusRecorderMiddleware to the middleware specified in the config as a convenience.

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers HTTP flags with pflags

type Metrics

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

Metrics is a bundle of prometheus HTTP metrics recorders

func NewMetrics

func NewMetrics(registry prometheus.Registerer, mustRegister bool) Metrics

NewMetrics creates and returns a metrics bundle. The user may optionally specify an existing Prometheus Registry. If no Registry is provided, the global Prometheus Registry is used. Finally, if mustRegister is true, and a registration error is encountered, the application will panic.

func (Metrics) Middleware

func (m Metrics) Middleware(next http.Handler) http.Handler

Middleware provides standard HTTP middleware for recording prometheus metrics on every request. Note that this middleware must be attached after writer.StatusRecorderMiddleware for HTTP response code tagging to function.

type Server

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

Server contains unexported fields and is used to start and manage the Server.

func (Server) Run

func (s Server) Run()

Run starts the web server, calling any provided preStart hooks and registering the provided muxes. The server runs until a cancellation signal is sent to exit. At that point, the server is stopped and any postShutdown hooks are called.

Note that cancelSignals defines the os.Signals that should cause the server to exit and shut down. If no cancelSignals are provided, this defaults to os.Interrupt. Note that if you override this value and still wish to handle os.Interrupt you _must_ additionally include that value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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