goutils/middleware/chain.go
mStar 9d803a94ee
Add middlewares
- 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
2024-11-26 17:30:05 +01:00

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
}