mirror of
				https://github.com/labstack/echo.git
				synced 2025-10-30 23:57:38 +02:00 
			
		
		
		
	Added new functions: Echo.Any & Echo.Match
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
		
							
								
								
									
										26
									
								
								echo.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								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) { | ||||
|   | ||||
							
								
								
									
										14
									
								
								echo_test.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user