20 lines
336 B
Go
20 lines
336 B
Go
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
|
|
}
|