Skip to content

Commit 8e421d9

Browse files
committed
Fixed #1019
Signed-off-by: Vishal Rana <[email protected]>
1 parent 0473c51 commit 8e421d9

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

echo.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,19 +414,19 @@ func (e *Echo) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
414414
// Any registers a new route for all HTTP methods and path with matching handler
415415
// in the router with optional route-level middleware.
416416
func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
417-
routes := make([]*Route, 0)
418-
for _, m := range methods {
419-
routes = append(routes, e.Add(m, path, handler, middleware...))
417+
routes := make([]*Route, len(methods))
418+
for i, m := range methods {
419+
routes[i] = e.Add(m, path, handler, middleware...)
420420
}
421421
return routes
422422
}
423423

424424
// Match registers a new route for multiple HTTP methods and path with matching
425425
// handler in the router with optional route-level middleware.
426426
func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
427-
routes := make([]*Route, 0)
428-
for _, m := range methods {
429-
routes = append(routes, e.Add(m, path, handler, middleware...))
427+
routes := make([]*Route, len(methods))
428+
for i, m := range methods {
429+
routes[i] = e.Add(m, path, handler, middleware...)
430430
}
431431
return routes
432432
}

group.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,21 @@ func (g *Group) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
7171
}
7272

7373
// Any implements `Echo#Any()` for sub-routes within the Group.
74-
func (g *Group) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) {
75-
for _, m := range methods {
76-
g.Add(m, path, handler, middleware...)
74+
func (g *Group) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
75+
routes := make([]*Route, len(methods))
76+
for i, m := range methods {
77+
routes[i] = g.Add(m, path, handler, middleware...)
7778
}
79+
return routes
7880
}
7981

8082
// Match implements `Echo#Match()` for sub-routes within the Group.
81-
func (g *Group) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) {
82-
for _, m := range methods {
83-
g.Add(m, path, handler, middleware...)
83+
func (g *Group) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
84+
routes := make([]*Route, len(methods))
85+
for i, m := range methods {
86+
routes[i] = g.Add(m, path, handler, middleware...)
8487
}
88+
return routes
8589
}
8690

8791
// Group creates a new sub-group with prefix and optional sub-group-level middleware.

0 commit comments

Comments
 (0)