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:
parent
9216043df5
commit
fec348385e
26
echo.go
26
echo.go
@ -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) {
|
||||||
|
14
echo_test.go
14
echo_test.go
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user