middleware

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2016 License: Apache-2.0 Imports: 9 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()
		i := &interceptor{ResponseWriter: w, statusCode: http.StatusOK}
		next.ServeHTTP(i, r)
		log.Infof("%s %s (%d) %s", r.Method, r.RequestURI, i.statusCode, time.Since(begin))
	})
})

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

Functions

This section is empty.

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.SummaryVec
}

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.

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

Jump to

Keyboard shortcuts

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