1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Added new functions: Echo.Any & Echo.Match

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-08-25 20:36:15 -07:00
parent 9216043df5
commit fec348385e
2 changed files with 40 additions and 0 deletions

26
echo.go
View File

@ -144,6 +144,18 @@ const (
) )
var ( var (
methods = [...]string{
CONNECT,
DELETE,
GET,
HEAD,
OPTIONS,
PATCH,
POST,
PUT,
TRACE,
}
//-------- //--------
// Errors // Errors
//-------- //--------
@ -298,6 +310,20 @@ func (e *Echo) Trace(path string, h Handler) {
e.add(TRACE, path, h) 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. // WebSocket adds a WebSocket route > handler to the router.
func (e *Echo) WebSocket(path string, h HandlerFunc) { func (e *Echo) WebSocket(path string, h HandlerFunc) {
e.Get(path, func(c *Context) (err error) { e.Get(path, func(c *Context) (err error) {

View File

@ -246,6 +246,20 @@ func TestEchoTrace(t *testing.T) {
testMethod(t, TRACE, "/", e) 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) { func TestEchoWebSocket(t *testing.T) {
e := New() e := New()
e.WebSocket("/ws", func(c *Context) error { e.WebSocket("/ws", func(c *Context) error {