middleware

package
v0.17.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logging = Func(func(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		begin := time.Now()
		uri := r.RequestURI
		i := &interceptor{ResponseWriter: w, statusCode: http.StatusOK}
		next.ServeHTTP(i, r)
		log.Infof("%s %s (%d) %s", r.Method, uri, i.statusCode, time.Since(begin))
	})
})

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

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 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

Jump to

Keyboard shortcuts

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