Documentation ¶
Overview ¶
Package adapter provides a method of connecting standard Go middleware handlers to Gin's Engine.
The adapter uses the request context to pass Gin's context through the wrapped handler and ensure the next middlware on the chain is called correctly.
Example of using it with the nosurf CSRF package
engine.Use(adapter.Wrap(nosurf.NewPure))
If the middleware you're using doesn't comply with the f(http.Handler) http.Handler interface, or if extra configuration of the middleware is required, use New instead:
nextHandler, wrapper := adapter.New() ns := nosurf.New(nextHandler) ns.SetFailureHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.Error(w, "Custom error about invalid CSRF tokens", http.StatusBadRequest) })) engine.Use(wrapper(ns))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a handler to be passed to middleware which will ensure the next handler in the chain is called correctly, along with a function that wraps the middleware's handler into a gin.HandlerFunc to be passed to Engine.Use.
If the middleware does not call the handler it's wrapping, Abort is called on the Gin context.
Types ¶
This section is empty.