middleware

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: AGPL-3.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const (
	StatusClientClosedRequest = 499
)

Variables

View Source
var (

	// BodySizeBuckets defines buckets for request/response body sizes.
	BodySizeBuckets = []float64{1 * mb, 2.5 * mb, 5 * mb, 10 * mb, 25 * mb, 50 * mb, 100 * mb, 250 * mb}
	// DefBuckets are histogram buckets for the response time (in seconds)
	// of a network service, including one that is responding very slowly.
	DefBuckets = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100}
)

Functions

func ExtractSampledTraceID

func ExtractSampledTraceID(ctx context.Context) (string, bool)

ExtractSampledTraceID works like ExtractTraceID but the returned bool is only true if the returned trace id is sampled.

func ExtractTraceID

func ExtractTraceID(ctx context.Context) (string, bool)

ExtractTraceID extracts the trace id, if any from the context.

func MakeLabelValue

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 HTTPAuth

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

func NewHTTPAuth

func NewHTTPAuth(log log.Logger) *HTTPAuth

func (HTTPAuth) Wrap

func (h HTTPAuth) Wrap(next http.Handler) http.Handler

type HTTPFakeAuth

type HTTPFakeAuth struct{}

func (HTTPFakeAuth) Wrap

func (h HTTPFakeAuth) Wrap(next http.Handler) http.Handler

type Instrument

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

Instrument is a Middleware which records timings for every HTTP request

func NewInstrument

func NewInstrument(routeMatcher RouteMatcher, defBuckets []float64, prefix string) (*Instrument, error)

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 middleware, and allows middlewares to wrap handlers.

func Merge

func Merge(middlewares ...Interface) Interface

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

type Log

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

func NewLoggingMiddleware

func NewLoggingMiddleware(logger log.Logger) *Log

func (Log) Wrap

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

Wrap implements commons middleware interface

type RequestLimits

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

func NewRequestLimitsMiddleware

func NewRequestLimitsMiddleware(maxRequestBodySize int64, logger log.Logger) *RequestLimits

func (RequestLimits) Wrap

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

type RouteMatcher

type RouteMatcher interface {
	Match(*http.Request, *mux.RouteMatch) bool
}

RouteMatcher matches routes

type Tracer

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

Tracer is a middleware which traces incoming requests.

func NewTracer

func NewTracer(routeMatcher RouteMatcher, tracer opentracing.Tracer) *Tracer

func (Tracer) Wrap

func (t Tracer) Wrap(next http.Handler) http.Handler

Wrap implements Interface

Jump to

Keyboard shortcuts

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