Documentation ¶
Index ¶
- Variables
- func GetLogger(r *http.Request) log.Logger
- func GetMetrics(r *http.Request) metrics.MetricsRecorder
- func GetMonitor(r *http.Request) monitoring.Monitor
- func GetRequestID(r *http.Request) string
- func LogRequest(next http.Handler) http.Handler
- func Recoverer(next http.Handler) http.Handler
- func WithBasicAuth(authorisedUser, authorisedPassword string) func(next http.Handler) http.Handler
- func WithLogger(base log.Logger) func(next http.Handler) http.Handler
- func WithMetrics(metrics metrics.MetricsRecorder) func(next http.Handler) http.Handler
- func WithMonitor(monitor monitoring.Monitor) func(next http.Handler) http.Handler
- func WithRequestID(next http.Handler) http.Handler
- func WithStatusWrappingResponseWriter(next http.Handler) http.Handler
- type MiddlewareMux
- type Response
- type StatusWrappingResponseWriter
Constants ¶
This section is empty.
Variables ¶
var ErrAuthentication = errors.New("Authentication Error")
ErrAuthentication returned when Authentication has failed.
Functions ¶
func GetMetrics ¶
func GetMetrics(r *http.Request) metrics.MetricsRecorder
Get the MetricsRecorder stored in request context, or nil.
func GetMonitor ¶
func GetMonitor(r *http.Request) monitoring.Monitor
Get the Monitor stored in request context, or nil.
func GetRequestID ¶
Get the RequestID stored in request context, or empty.
func LogRequest ¶
LogRequest logs the start and end of a request
func Recoverer ¶
Recoverer recovers from panic and prints a log line to the request's logger, if available.
func WithBasicAuth ¶
func WithLogger ¶
WithLogger adds a "logger" key to the request context. it will use a requestID as a standard field, if available
func WithMetrics ¶
WithMetrics adds a "metrics" key to the request context.
func WithMonitor ¶
WithMonitor adds a "monitor" key to the request context.
func WithRequestID ¶
WithRequestID adds a "requestID" key to the request context.
Types ¶
type MiddlewareMux ¶
type MiddlewareMux struct {
// contains filtered or unexported fields
}
MiddlewareMux wraps the default router with a couple of methods to allow easier middleware usage.
func NewMiddlewareMux ¶
func NewMiddlewareMux() *MiddlewareMux
func NewMiddlewareMuxWithDefaults ¶
func NewMiddlewareMuxWithDefaults(logger log.Logger, recorder metrics.MetricsRecorder, monitor monitoring.Monitor) *MiddlewareMux
NewMiddlewareMuxWithDefaults sets up a basic middleware mux with default middleware of logger, metrics, monitoring, request id and status wrapping
func (*MiddlewareMux) Handle ¶
func (mm *MiddlewareMux) Handle(pattern string, handler http.Handler)
Handle a route
func (*MiddlewareMux) ServeHTTP ¶
func (mm *MiddlewareMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Response ¶
A Response contains information to be written
func EmptyResponse ¶
EmptyResponse returns a Response object without a body
func JSONErrorResponse ¶
JSONErrorResponse returns a Response object formatted to display given error as JSON
func JSONResponse ¶
JSONResponse builds a Response with the body formatted as JSON
func (*Response) WriteTo ¶
func (r *Response) WriteTo(out http.ResponseWriter)
WriteTo writes the Response to a http.ResponseWriter
type StatusWrappingResponseWriter ¶
type StatusWrappingResponseWriter struct { http.ResponseWriter Status int }
StatusWrappingResponseWriter wraps a http.ResponseWriter, overriding WriteHeader to keep a record of the Status set.
func (*StatusWrappingResponseWriter) WriteHeader ¶
func (rw *StatusWrappingResponseWriter) WriteHeader(status int)