Documentation ¶
Index ¶
- Constants
- func DefaultStack(appInfo AppInfo, lgr Logger, orig http.Handler) http.Handler
- func Gzip(level int, next http.Handler) http.Handler
- func GzipMW(level int) alice.Constructor
- func NewAuditMW(info AppInfo, logger Logger) alice.Constructor
- func NewHealthChecksMW(basePath string) alice.Constructor
- func NewProfiler(next http.Handler) http.Handler
- func NewRecoveryMW(appName string, lgr Logger) alice.Constructor
- type AppInfo
- type Audit
- type CounterMetric
- type GaugeFloat64Metric
- type GaugeMetric
- type HealtCheckData
- type HealthChecks
- type HistogramMetric
- type Logger
- type MeterMetric
- type Profiler
- type Recovery
- type TimerMetric
Constants ¶
const ( BestCompression = gzip.BestCompression BestSpeed = gzip.BestSpeed DefaultCompression = gzip.DefaultCompression NoCompression = gzip.NoCompression )
These compression constants are copied from the compress/gzip package.
Variables ¶
This section is empty.
Functions ¶
func DefaultStack ¶
DefaultStack sets up the default middlewares
func Gzip ¶
Gzip returns a handler which will handle the Gzip compression in ServeHTTP. Valid values for level are identical to those in the compress/gzip package.
func GzipMW ¶
func GzipMW(level int) alice.Constructor
GzipMW returns a middleware which will handle the Gzip compression in ServeHTTP. Valid values for level are identical to those in the compress/gzip package.
func NewAuditMW ¶
func NewAuditMW(info AppInfo, logger Logger) alice.Constructor
NewAuditMW returns a new Audit middleware
func NewHealthChecksMW ¶
func NewHealthChecksMW(basePath string) alice.Constructor
NewHealthChecksMW creates a new health check middleware at the specified path
func NewProfiler ¶
NewProfiler creates a middleware for profiling
func NewRecoveryMW ¶
func NewRecoveryMW(appName string, lgr Logger) alice.Constructor
NewRecoveryMW returns a new instance of Recovery middleware which traps panics
Types ¶
type AppInfo ¶
type AppInfo struct { Name string `json:"name"` Version string `json:"version"` Commit string `json:"commit"` BasePath string `json:"basePath"` Pid int `json:"pid"` }
AppInfo the information describing the component for this API
type Audit ¶
type Audit struct { // logger is the Logger instance used to log messages with the Audit middleware Logger Logger // contains filtered or unexported fields }
Audit is a middleware handler that logs the request as it goes in and the response as it goes out.
type CounterMetric ¶
type CounterMetric struct {
Count int64 `json:"count"`
}
CounterMetric represents a value that increases or decreases
type GaugeFloat64Metric ¶
type GaugeFloat64Metric struct {
Value float64 `json:"value"`
}
GaugeFloat64Metric represents a float64 measurement
type GaugeMetric ¶
type GaugeMetric struct {
Value int64 `json:"value"`
}
GaugeMetric represents measurements.
type HealtCheckData ¶
type HealtCheckData struct {
Error string `json:"error"`
}
HealtCheckData shows error status if any for a health check
type HealthChecks ¶
type HealthChecks struct {
// contains filtered or unexported fields
}
HealthChecks is a middleware that serves healthcheck information
func NewHealthChecks ¶
func NewHealthChecks(basePath string, next http.Handler) *HealthChecks
NewHealthChecks creates a new health check middleware at the specified path
func (*HealthChecks) ServeHTTP ¶
func (h *HealthChecks) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP is the middleware interface implementation
type HistogramMetric ¶
type HistogramMetric struct { Count int64 `json:"count"` Min int64 `json:"min"` Max int64 `json:"max"` Mean float64 `json:"mean"` StdDev float64 `json:"stdDev"` Median float64 `json:"median"` P75 float64 `json:"p75"` P95 float64 `json:"p95"` P99 float64 `json:"p99"` P999 float64 `json:"p999"` Unit string `json:"unit,omitempty"` }
HistogramMetric shows a histogram metric
type Logger ¶
type Logger interface { Debugf(string, ...interface{}) Infof(string, ...interface{}) Errorf(string, ...interface{}) }
Logger interface to allow different logging libaries to be used with this middleware
type MeterMetric ¶
type MeterMetric struct { Count int64 `json:"count"` M1 float64 `json:"m1"` M5 float64 `json:"m5"` M15 float64 `json:"m15"` Mean float64 `json:"mean"` }
MeterMetric represents a metered value with 1-minute, 5-minute and 15 minute averages as well as a mean
type Profiler ¶
type Profiler struct {
// contains filtered or unexported fields
}
Profiler exposes net/http/pprof as a middleware
type Recovery ¶
Recovery is a middleware that recovers from any panics and writes a 500 if there was one.
func NewRecovery ¶
NewRecovery returns a new instance of Recovery
type TimerMetric ¶
type TimerMetric struct { Rate MeterMetric `json:"rate"` Duration HistogramMetric `json:"duration"` }
TimerMetric is a combination of a meter metric and a histogram metric, typically used for tracing time spent and call counts for example