Files

16 lines
481 B
Go
Raw Permalink Normal View History

2026-09-15 01:38:15 +09:00
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
}