diff --git a/chain.go b/chain.go index a2278414..838c5b11 100644 --- a/chain.go +++ b/chain.go @@ -3,7 +3,7 @@ package chi import "net/http" // Chain returns a Middlewares type from a slice of middleware handlers. -func Chain(middlewares ...func(http.Handler) http.Handler) Middlewares { +func Chain(middlewares Middlewares) Middlewares { return Middlewares(middlewares) } @@ -33,7 +33,7 @@ func (c *ChainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // chain builds a http.Handler composed of an inline middleware stack and endpoint // handler in the order they are passed. -func chain(middlewares []func(http.Handler) http.Handler, endpoint http.Handler) http.Handler { +func chain(middlewares Middlewares, endpoint http.Handler) http.Handler { // Return ahead of time if there aren't any middlewares for the chain if len(middlewares) == 0 { return endpoint diff --git a/chi.go b/chi.go index f650116a..99e1cf69 100644 --- a/chi.go +++ b/chi.go @@ -61,6 +61,11 @@ func NewRouter() *Mux { return NewMux() } +// middleware type alias (for chain.go) +type Middleware = func(http.Handler) http.Handler + +type Middlewares Middleware[] + // Router consisting of the core routing methods used by chi's Mux, // using only the standard net/http. type Router interface {