middleware

package
v0.0.0-...-840d408 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterResponse

func AfterResponse(hook func(http.ResponseWriter, *http.Request, int) error, skippers ...Skipper) func(http.Handler) http.Handler

AfterResponse make a middleware which will call hook after the next handler

func BeforeRequest

func BeforeRequest(hook func(*http.Request) error, skippers ...Skipper) func(http.Handler) http.Handler

BeforeRequest make a middleware which will call hook before the next handler

func Chain

func Chain(middlewares ...Middleware) func(http.Handler) http.Handler

Chain make middlewares together

func MethodAndPathSkipper

func MethodAndPathSkipper(method string, re *regexp.Regexp) func(r *http.Request) bool

MethodAndPathSkipper returns skipper which will skip the middleware when r.Method equals the method and r.URL.Path matches the re when method is "*" it equals all http method

func NegativeSkipper

func NegativeSkipper(skipper Skipper) func(*http.Request) bool

NegativeSkipper returns skipper which is negative of the input skipper

func New

func New(fn func(http.ResponseWriter, *http.Request, http.Handler), skippers ...Skipper) func(http.Handler) http.Handler

New make a middleware from fn which type is func(w http.ResponseWriter, r *http.Request, next http.Handler)

func WithMiddlewares

func WithMiddlewares(handler http.Handler, middlewares ...Middleware) http.Handler

WithMiddlewares apply the middlewares to the handler. The middlewares are executed in the order that they are applied

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware receives a handler and returns another handler. The returned handler can do some customized task according to the requirement

type Skipper

type Skipper func(*http.Request) bool

Skipper defines a function to skip middleware. Returning true skips processing the middleware.

Jump to

Keyboard shortcuts

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