chain builds a http.Handler composed of an inline middleware stack and endpoint handler in the order they are passed.
(middlewares []func(http.Handler) http.Handler, endpoint http.Handler)
| 34 | // chain builds a http.Handler composed of an inline middleware stack and endpoint |
| 35 | // handler in the order they are passed. |
| 36 | func chain(middlewares []func(http.Handler) http.Handler, endpoint http.Handler) http.Handler { |
| 37 | // Return ahead of time if there aren't any middlewares for the chain |
| 38 | if len(middlewares) == 0 { |
| 39 | return endpoint |
| 40 | } |
| 41 | |
| 42 | // Wrap the end handler with the middleware chain |
| 43 | h := middlewares[len(middlewares)-1](endpoint) |
| 44 | for i := len(middlewares) - 2; i >= 0; i-- { |
| 45 | h = middlewares[i](h) |
| 46 | } |
| 47 | |
| 48 | return h |
| 49 | } |
no outgoing calls
no test coverage detected