pub
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package middleware
|
||||
|
||||
import "net/http"
|
||||
|
||||
// Middleware defines a function that wraps an http.Handler
|
||||
type Middleware func(http.Handler) http.Handler
|
||||
|
||||
// Chain constructs a new http.Handler by chaining multiple Middlewares around a final http.Handler
|
||||
func Chain(handler http.Handler, middlewares ...Middleware) http.Handler {
|
||||
// Loop in reverse to preserve the order of execution
|
||||
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||
handler = middlewares[i](handler)
|
||||
}
|
||||
return handler
|
||||
}
|
||||
Reference in New Issue
Block a user