middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogFailed = Log{
	LogSuccess: false,
}

LogFailed middleware logs each HTTP request method, path, response code and duration for non-2xx HTTP requests.

View Source
var Logging = Log{
	LogSuccess: true,
}

Logging middleware logs each HTTP request method, path, response code and duration for all HTTP requests.

Functions

func MakeLabelValue added in v0.16.0

func MakeLabelValue(path string) string

MakeLabelValue converts a Gorilla mux path to a string suitable for use in a Prometheus label value.

Types

type ErrorHandler added in v1.0.0

type ErrorHandler struct {
	Code    int
	Handler http.Handler
}

ErrorHandler lets you call an alternate http handler upon a certain response code. Note it will assume a 200 if the wrapped handler does not write anything

func (ErrorHandler) Wrap added in v1.0.0

func (e ErrorHandler) Wrap(next http.Handler) http.Handler

Wrap implements Middleware

type Func

type Func func(http.Handler) http.Handler

Func is to Interface as http.HandlerFunc is to http.Handler

func (Func) Wrap

func (m Func) Wrap(next http.Handler) http.Handler

Wrap implements Interface

type Instrument

type Instrument struct {
	RouteMatcher interface {
		Match(*http.Request, *mux.RouteMatch) bool
	}
	Duration *prometheus.HistogramVec
}

Instrument is a Middleware which records timings for every HTTP request

func (Instrument) Wrap

func (i Instrument) Wrap(next http.Handler) http.Handler

Wrap implements middleware.Interface

type Interface

type Interface interface {
	Wrap(http.Handler) http.Handler
}

Interface is the shared contract for all middlesware, and allows middlesware to wrap handlers.

var Identity Interface = Func(func(h http.Handler) http.Handler { return h })

Identity is an Interface which doesn't do anything.

func Merge

func Merge(middlesware ...Interface) Interface

Merge produces a middleware that applies multiple middlesware in turn; ie Merge(f,g,h).Wrap(handler) == f.Wrap(g.Wrap(h.Wrap(handler)))

func PathReplace added in v0.15.0

func PathReplace(replacement string) Interface

PathReplace replcase Request.RequestURI with the specified string.

func PathRewrite added in v0.15.0

func PathRewrite(regexp *regexp.Regexp, replacement string) Interface

PathRewrite supports regex matching and replace on Request URIs

type Log added in v1.0.0

type Log struct {
	LogSuccess bool // LogSuccess true -> log successful queries; false -> only log failed queries
}

Log middleware logs http requests

func (Log) Wrap added in v1.0.0

func (l Log) Wrap(next http.Handler) http.Handler

Wrap implements Middleware

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL