MCPcopy
hub / github.com/labstack/echo / buildRouterChains

Method buildRouterChains

echo.go:395–408  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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.
395func (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//

Callers 3

NewFunction · 0.95
PreMethod · 0.95
UseMethod · 0.95

Calls 2

applyMiddlewareFunction · 0.85
RouteMethod · 0.65

Tested by

no test coverage detected