Skip to content

Commit 34f3f42

Browse files
hyorimitsualdas
authored andcommitted
docs: correct Any godoc to reflect true arbitrary-method matching
1 parent 70b31c2 commit 34f3f42

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

echo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,11 @@ func (e *Echo) RouteNotFound(path string, h HandlerFunc, m ...MiddlewareFunc) Ro
578578
return e.Add(RouteNotFound, path, h, m...)
579579
}
580580

581-
// Any registers a new route for all HTTP methods (supported by Echo) and path with matching handler
582-
// in the router with optional route-level middleware.
581+
// Any registers a new route for a path with matching handler in the router with optional
582+
// route-level middleware. Panics on error. The route matches any HTTP method in the request,
583+
// including methods not known to Echo, by registering a single RouteAny route.
583584
//
584-
// Note: this method only adds specific set of supported HTTP methods as handler and is not true
585-
// "catch-any-arbitrary-method" way of matching requests.
585+
// A method-specific route registered for the same path takes precedence over the Any route.
586586
func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) RouteInfo {
587587
return e.Add(RouteAny, path, handler, middleware...)
588588
}

echo_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,20 @@ func TestEcho_Any(t *testing.T) {
942942
assert.Equal(t, `OK from ANY`, body)
943943
}
944944

945+
func TestEcho_Any_matchesArbitraryMethod(t *testing.T) {
946+
e := New()
947+
948+
e.Any("/activate", func(c *Context) error {
949+
return c.String(http.StatusTeapot, "OK from ANY")
950+
})
951+
952+
// ARBITRARY-METHOD is not one of Echo's known HTTP methods; the RouteAny
953+
// fallback must still match it.
954+
status, body := request("ARBITRARY-METHOD", "/activate", e)
955+
assert.Equal(t, http.StatusTeapot, status)
956+
assert.Equal(t, `OK from ANY`, body)
957+
}
958+
945959
func TestEcho_Any_hasLowerPriority(t *testing.T) {
946960
e := New()
947961

router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func (r *DefaultRouter) Remove(method string, path string) error {
485485
}
486486

487487
// AddRouteError is error returned by Router.Add containing information what actual route adding failed. Useful for
488-
// mass adding (i.e. Any() routes)
488+
// mass adding (i.e. Match() routes)
489489
type AddRouteError struct {
490490
Err error
491491
Method string

0 commit comments

Comments
 (0)