middleware/middleware.go

20 lines
336 B
Go
Raw Normal View History

package middleware
import (
"net/http"
)
// Wrap converts a list of middlewares to nested calls in reverse order
func Wrap(handler http.Handler, mws ...func(http.Handler) http.Handler) http.Handler {
if len(mws) == 0 {
return handler
}
res := handler
for i := len(mws) - 1; i >= 0; i-- {
res = mws[i](res)
}
return res
}