mStar
9d803a94ee
- Builder for chaining multiple middlewares on top of a base handler - Middleware for adding a map of values to the request context - Middleware for adding zerolog logging to the request
16 lines
273 B
Go
16 lines
273 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"slices"
|
|
)
|
|
|
|
type HandlerBuilder func(http.Handler) http.Handler
|
|
|
|
func ChainMiddlewares(base http.Handler, links ...HandlerBuilder) http.Handler {
|
|
slices.Reverse(links)
|
|
for _, f := range links {
|
|
base = f(base)
|
|
}
|
|
return base
|
|
}
|