1
0
mirror of https://github.com/labstack/echo.git synced 2025-03-11 14:49:56 +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,
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.
@ -513,7 +514,11 @@ func (e *Echo) URL(h HandlerFunc, params ...interface{}) string {
// Routes returns the registered routes.
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.

View File

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