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

Interface Router

router.go:21–45  ·  view source on GitHub ↗

Router is interface for routing request contexts to registered routes. Contract between Echo/Context instance and the router: - all routes must be added through methods on echo.Echo instance. Reason: Echo instance uses RouteInfo.Params() length to allocate slice for paths parameters (see `Echo.cont

Source from the content-addressed store, hash-verified

19// - Context.InitializeRoute (IMPORTANT! to reduce allocations use same slice that c.PathValues() returns)
20// - Optionally can set additional information to Context with Context.Set
21type Router interface {
22 // Add registers Routable with the Router and returns registered RouteInfo.
23 //
24 // Router may change Route.Path value in returned RouteInfo.Path.
25 // Router generates RouteInfo.Parameters values from Route.Path.
26 // Router generates RouteInfo.Name value if it is not provided.
27 Add(routable Route) (RouteInfo, error)
28
29 // Remove removes route from the Router.
30 //
31 // Router may choose not to implement this method.
32 Remove(method string, path string) error
33
34 // Routes returns information about all registered routes
35 Routes() Routes
36
37 // Route searches Router for matching route and applies it to the given context. In case when no matching method
38 // was not found (405) or no matching route exists for path (404), router will return its implementation of 405/404
39 // handler function.
40 //
41 // Router must populate Context during Router.Route call with:
42 // - Context.InitializeRoute() (IMPORTANT! to reduce allocations use same slice that c.PathValues() returns)
43 // - optionally can set additional information to Context with Context.Set()
44 Route(c *Context) HandlerFunc
45}
46
47const (
48 // NotFoundRouteName is name of RouteInfo returned when router did not find matching route (404: not found).

Implementers 2

DefaultRouterrouter.go
concurrentRouterrouter_concurrent.go

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…