http

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

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       Middleware                                                         // 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.

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(serverName string, registry prometheus.Registerer, mustRegister bool) Metrics

NewMetrics creates and returns a metrics bundle given a server name. 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(sr *writer.StatusRecorder, r *http.Request) (func(), *http.Request)

Middleware provides standard HTTP middleware for recording prometheus metrics on every request

type Middleware

type Middleware []MiddlewareFunc

Middleware defines a collection of middleware functions.

type MiddlewareFunc

type MiddlewareFunc func(*writer.StatusRecorder, *http.Request) (func(), *http.Request)

MiddlewareFunc defines a middleware function used in processing HTTP Requests. Request preprocessing may be specified in the body of the middleware function call. If post-processing is required, please use the returned deferable func() to encapsulate that logic.

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