From 8e421d9773977693e98d2201c9f47bfbc02d2f48 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Fri, 22 Dec 2017 12:09:52 -0800 Subject: [PATCH] Fixed #1019 Signed-off-by: Vishal Rana --- echo.go | 12 ++++++------ group.go | 16 ++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/echo.go b/echo.go index 77c238d0..98bcfe7a 100644 --- a/echo.go +++ b/echo.go @@ -414,9 +414,9 @@ func (e *Echo) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route { // Any registers a new route for all HTTP methods and path with matching handler // in the router with optional route-level middleware. func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route { - routes := make([]*Route, 0) - for _, m := range methods { - routes = append(routes, e.Add(m, path, handler, middleware...)) + routes := make([]*Route, len(methods)) + for i, m := range methods { + routes[i] = e.Add(m, path, handler, middleware...) } return routes } @@ -424,9 +424,9 @@ func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFun // Match registers a new route for multiple HTTP methods and path with matching // handler in the router with optional route-level middleware. func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route { - routes := make([]*Route, 0) - for _, m := range methods { - routes = append(routes, e.Add(m, path, handler, middleware...)) + routes := make([]*Route, len(methods)) + for i, m := range methods { + routes[i] = e.Add(m, path, handler, middleware...) } return routes } diff --git a/group.go b/group.go index 6ae32372..49bbea28 100644 --- a/group.go +++ b/group.go @@ -71,17 +71,21 @@ func (g *Group) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route { } // Any implements `Echo#Any()` for sub-routes within the Group. -func (g *Group) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) { - for _, m := range methods { - g.Add(m, path, handler, middleware...) +func (g *Group) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route { + routes := make([]*Route, len(methods)) + for i, m := range methods { + routes[i] = g.Add(m, path, handler, middleware...) } + return routes } // Match implements `Echo#Match()` for sub-routes within the Group. -func (g *Group) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) { - for _, m := range methods { - g.Add(m, path, handler, middleware...) +func (g *Group) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route { + routes := make([]*Route, len(methods)) + for i, m := range methods { + routes[i] = g.Add(m, path, handler, middleware...) } + return routes } // Group creates a new sub-group with prefix and optional sub-group-level middleware.