wrapHandlers applies all registered middleware to a handler slice. It always operates on the original handlers, so calling it multiple times produces a correctly single-wrapped result.
(handlers []Handler)
| 417 | // It always operates on the original handlers, so calling it multiple |
| 418 | // times produces a correctly single-wrapped result. |
| 419 | func (server *Server) wrapHandlers(handlers []Handler) []Handler { |
| 420 | if len(server.middlewares) == 0 { |
| 421 | return handlers |
| 422 | } |
| 423 | wrapped := make([]Handler, len(handlers)) |
| 424 | for k, h := range handlers { |
| 425 | w := h |
| 426 | for i := len(server.middlewares) - 1; i >= 0; i-- { |
| 427 | w = server.middlewares[i](w) |
| 428 | } |
| 429 | wrapped[k] = w |
| 430 | } |
| 431 | return wrapped |
| 432 | } |
| 433 | |
| 434 | // Context returns the underlying request context. |
| 435 | func (c *Ctx) Context() context.Context { |