Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDefaultClient ¶ added in v0.22.0
func NewDefaultClient(metrics Metrics, roundTripper http.RoundTripper) http.Client
NewDefaultClient constructs the default HTTP Client with middleware. Providing an HTTP RoundTripper is optional. If `nil` is received, the DefaultClient will be used.
func ParseTime ¶ added in v0.15.0
ParseTime reads and parses from the query parameters to the supplied request a Time value corresponding to fieldName. An error is returned if a Time could not be parsed from the given field. The zero-valued Time is returned if the given field is not present in the query parameters to the supplied request.
Types ¶
type ClientMiddleware ¶ added in v0.22.0
ClientMiddleware defines an HTTP Client middleware function. The function is called prior to invoking the transport roundtrip, and the returned response function is called after the response has been received from the client.
type Config ¶
type Config struct {
Name string // Name of the HTTP Server
Address string // Address on which the server will be accessible
Port uint16 // 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 ¶
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 ¶
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 ¶
RegisterFlags registers HTTP flags with pflags
type Coordinates ¶ added in v0.15.0
Coordinates is an encapsulation of geospatial coordinates in decimal degrees.
func ParseCoordinates ¶ added in v0.15.0
func ParseCoordinates(r *http.Request, latFieldName, lonFieldName string) (*Coordinates, error)
ParseCoordinates reads and parses from the query parameters to the supplied request latitude and logitude corresponding to latFieldName and lonFieldName, respectively. An error is returned if only one of the named fields is present, if either value cannot be parsed as a float, or if either value is out of range for decimal latitude and longitude. The returned struct reference is nil if none of latFieldName or lonFieldName are present in the query parameters to the given request.
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) ClientMiddleware ¶ added in v0.22.0
func (m Metrics) ClientMiddleware(r *http.Request) (*http.Request, func(*http.Response) error, error)
ClientMiddleware is middleware for use in HTTP Clients for capturing prometheus metrics
func (Metrics) Middleware ¶
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 MiddlewareRoundTripper ¶ added in v0.22.0
type MiddlewareRoundTripper struct {
RoundTripper http.RoundTripper
// Middleware consist of a function which is called prior to the execution of a request. This
// function returns the potentially modified request, the post-response handler, and an error,
// if any. The response handler is invoked after the HTTP request has been made.
//
// Middleware are called in the order they are specified. In otherwords, the first item in the
// slice is the first middleware applied, and the last item in the slice is the last middleware
// applied. Each response handler is called in the reverse order of the middleware. Meaning,
// the last middleware called will be the first to have its response handler called, and
// likewise, the first middleware called will be the last to have its handler called.
Middleware []ClientMiddleware
}
MiddlewareRoundTripper implements a proxied net/http RoundTripper so that http requests may be decorated with middleware
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.