middleware

package
v4.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultTags

func DefaultTags(r *http.Request) []interface{}

DefaultTags extracts the method and path from the request.

func WithCommon

func WithCommon(ctx context.Context, h http.Handler, fns ...TagsFunc) http.Handler

WithCommon wraps the handler with the commonly used middlewares.

func WithContext

func WithContext(ctx context.Context, h http.Handler) http.Handler

WithContext set the context on the request.

func WithQueryNormalizer

func WithQueryNormalizer(h http.Handler) http.Handler

WithQueryNormalizer fixes wrong php query string handling as array

func WithQueryTransformer

func WithQueryTransformer(h http.Handler, t QueryTransformer) http.HandlerFunc

WithQueryTransformer returns an http handler that transforms query parameters using the passed transformer.

func WithQueryTransformerFunc

func WithQueryTransformerFunc(h http.Handler, keys []string, fn StringTransformerFunc) http.Handler

WithQueryTransformerFunc returns an http handler that transforms query parameters using the passed function.

func WithRecovery

func WithRecovery(h http.Handler, opts ...RecoveryFunc) http.Handler

WithRecovery recovers from panics and log the error.

func WithRequestStats

func WithRequestStats(h http.Handler, fns ...TagsFunc) http.Handler

WithRequestStats collects statistics about the request.

func WithResponseTime

func WithResponseTime(h http.Handler, fns ...TagsFunc) http.Handler

WithResponseTime reports the response time.

Types

type QueryTransformer

type QueryTransformer struct {
	// contains filtered or unexported fields
}

QueryTransformer transforms query parameters with the registered functions.

func (*QueryTransformer) Register

func (t *QueryTransformer) Register(keys []string, fn StringTransformerFunc)

Register registers a function as a transformer for the given set of keys.

type Recovery

type Recovery struct {
	// contains filtered or unexported fields
}

Recovery is a middleware that will recover from panics and logs the error.

func (*Recovery) ServeHTTP

func (m *Recovery) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the request.

type RecoveryFunc

type RecoveryFunc func(*Recovery)

RecoveryFunc is used to configure the recovery handler.

func WithoutStack

func WithoutStack() RecoveryFunc

WithoutStack disables the stack trace dump from the recovery log.

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter

	// Status returns the status code of the response or 0 if the response has
	// not be written.
	Status() int
}

ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response.

func NewResponseWriter

func NewResponseWriter(rw http.ResponseWriter) ResponseWriter

NewResponseWriter create a new ResponseWriter.

type StringTransformerFunc

type StringTransformerFunc func(string) string

StringTransformerFunc represents a function that transforms a string into another string.

type TagsFunc

type TagsFunc func(*http.Request) []interface{}

TagsFunc returns a set of tags from a request

Jump to

Keyboard shortcuts

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