middleware

package
v0.0.0-...-8e8e47b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateChain

func CreateChain(mw []Middleware, finalHandlerFunc http.HandlerFunc) http.HandlerFunc

CreateChain returns a http.HandlerFunc that invokes each middleware in order then the final http.HandlerFunc.

Types

type Middleware

type Middleware func(next http.HandlerFunc) http.HandlerFunc

Middleware functions are invoked each time the server handles a route. The chain of middleware is followed until the final handler is reached. The middleware must call next(w, r) if the middleware does not handle the request.

For example:

middleware := func(next http.HandlerFunc) http.HandlerFunc {
    return func(writer http.ResponseWriter, request *http.Request) {
        // Do middleware actions here.
        // Calling next to invoke the next middleware or request handler.
        next(writer, request)
    }
}

Jump to

Keyboard shortcuts

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