buildRouterChains compiles the global and pre-middleware chains once so that ServeHTTP does not have to re-wrap middleware closures on every request. It must be called whenever e.middleware or e.premiddleware changes (i.e. from Use/Pre). This is safe because middleware must not be mutated after the
()
| 393 | // re-wrap middleware closures on every request. It must be called whenever e.middleware or e.premiddleware |
| 394 | // changes (i.e. from Use/Pre). This is safe because middleware must not be mutated after the server starts. |
| 395 | func (e *Echo) buildRouterChains() { |
| 396 | // dispatch is the terminal of the global chain: it invokes the handler resolved during routing. |
| 397 | dispatch := func(c *Context) error { |
| 398 | return c.handler(c) |
| 399 | } |
| 400 | e.chain = applyMiddleware(dispatch, e.middleware...) |
| 401 | |
| 402 | // route performs routing (storing the matched handler on the Context) and then runs the global chain. |
| 403 | route := func(c *Context) error { |
| 404 | c.handler = e.router.Route(c) |
| 405 | return e.chain(c) |
| 406 | } |
| 407 | e.preChain = applyMiddleware(route, e.premiddleware...) |
| 408 | } |
| 409 | |
| 410 | // NewContext returns a new Context instance. |
| 411 | // |
no test coverage detected