1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-15 01:34:53 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-05-22 08:45:36 -07:00
parent 702e6d0967
commit c24f06e7cb
2 changed files with 9 additions and 4 deletions

View File

@ -471,7 +471,8 @@ func (e *Echo) add(method, path string, handler HandlerFunc, middleware ...Middl
Path: path, Path: path,
Handler: name, Handler: name,
} }
e.router.routes = append(e.router.routes, r) e.router.routes[method+path] = r
// e.router.routes = append(e.router.routes, r)
} }
// Group creates a new router group with prefix and optional group-level middleware. // Group creates a new router group with prefix and optional group-level middleware.
@ -513,7 +514,11 @@ func (e *Echo) URL(h HandlerFunc, params ...interface{}) string {
// Routes returns the registered routes. // Routes returns the registered routes.
func (e *Echo) Routes() []Route { func (e *Echo) Routes() []Route {
return e.router.routes routes := []Route{}
for _, v := range e.router.routes {
routes = append(routes, v)
}
return routes
} }
// AcquireContext returns an empty `Context` instance from the pool. // AcquireContext returns an empty `Context` instance from the pool.

View File

@ -5,7 +5,7 @@ type (
// request matching and URL path parameter parsing. // request matching and URL path parameter parsing.
Router struct { Router struct {
tree *node tree *node
routes []Route routes map[string]Route
echo *Echo echo *Echo
} }
node struct { node struct {
@ -45,7 +45,7 @@ func NewRouter(e *Echo) *Router {
tree: &node{ tree: &node{
methodHandler: new(methodHandler), methodHandler: new(methodHandler),
}, },
routes: []Route{}, routes: make(map[string]Route),
echo: e, echo: e,
} }
} }