middleware

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HeadersFromContext

func HeadersFromContext(ctx context.Context) http.Header

HeadersFromContext retrieves HTTP headers from the given context. It takes a single parameter ctx of type context.Context. It returns an http.Header containing the headers if present in the context, or nil if the context is nil or does not contain headers.

func NewErrorHandlingMiddleware added in v0.3.0

func NewErrorHandlingMiddleware() func(next wasabi.RequestHandler) wasabi.RequestHandler

NewErrorHandlingMiddleware creates a middleware that handles errors and panics during request handling. It takes no parameters and returns a function that wraps a wasabi.RequestHandler. The returned function logs any errors or panics that occur during the handling of a request.

func NewHeadersMiddleware

func NewHeadersMiddleware() func(next http.Handler) http.Handler

NewHeadersMiddleware creates a middleware that injects request headers into the request context. It returns a function that takes an http.Handler and returns an http.Handler. This middleware allows subsequent handlers to access the request headers from the context.

func NewMetricsMiddleware added in v0.3.0

func NewMetricsMiddleware(scope string, skip func(wasabi.Request) bool) func(next wasabi.RequestHandler) wasabi.RequestHandler

NewMetricsMiddleware creates a middleware that records request duration metrics. It takes a scope of type string and returns a function that wraps a wasabi.RequestHandler. It returns a wasabi.RequestHandler that records the duration of each request and logs whether an error occurred. It panics if there is an error initializing the metric.

func NewQueryParamsMiddleware

func NewQueryParamsMiddleware() func(next http.Handler) http.Handler

NewQueryParamsMiddleware creates a middleware that extracts query parameters from the URL and stores them in the request context. It returns a function that takes an http.Handler and returns an http.Handler. This middleware allows subsequent handlers to access query parameters via the request context.

func QueryParamsFromContext

func QueryParamsFromContext(ctx context.Context) url.Values

QueryParamsFromContext retrieves URL query parameters from the given context. It takes a single parameter ctx of type context.Context. It returns url.Values containing the query parameters if present, or nil if the context is nil or does not contain query parameters.

Types

This section is empty.

Jump to

Keyboard shortcuts

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