Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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 ¶
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) 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 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.