diff --git a/echo.go b/echo.go index b586f1ae..54d3ce2a 100644 --- a/echo.go +++ b/echo.go @@ -144,6 +144,18 @@ const ( ) var ( + methods = [...]string{ + CONNECT, + DELETE, + GET, + HEAD, + OPTIONS, + PATCH, + POST, + PUT, + TRACE, + } + //-------- // Errors //-------- @@ -298,6 +310,20 @@ func (e *Echo) Trace(path string, h Handler) { e.add(TRACE, path, h) } +// Any adds a route > handler to the router for all HTTP methods. +func (e *Echo) Any(path string, h Handler) { + for _, m := range methods { + e.add(m, path, h) + } +} + +// Match adds a route > handler to the router for multiple HTTP methods provided. +func (e *Echo) Match(methods []string, path string, h Handler) { + for _, m := range methods { + e.add(m, path, h) + } +} + // WebSocket adds a WebSocket route > handler to the router. func (e *Echo) WebSocket(path string, h HandlerFunc) { e.Get(path, func(c *Context) (err error) { diff --git a/echo_test.go b/echo_test.go index 4c2d8254..49ad612b 100644 --- a/echo_test.go +++ b/echo_test.go @@ -246,6 +246,20 @@ func TestEchoTrace(t *testing.T) { testMethod(t, TRACE, "/", e) } +func TestEchoAny(t *testing.T) { // JFC + e := New() + e.Any("/", func(c *Context) error { + return c.String(http.StatusOK, "Any") + }) +} + +func TestEchoMatch(t *testing.T) { // JFC + e := New() + e.Match([]string{GET, POST}, "/", func(c *Context) error { + return c.String(http.StatusOK, "Match") + }) +} + func TestEchoWebSocket(t *testing.T) { e := New() e.WebSocket("/ws", func(c *Context) error {