diff --git a/README.md b/README.md index 8a2aa497..56ac66d1 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ import ( func main() { e := echo.New() - e.Get("/", func(c echo.Context) error { + e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") }) e.Run(standard.New(":1323")) @@ -78,10 +78,10 @@ Hello, World! on the page. ### Routing ```go -e.Post("/users", saveUser) -e.Get("/users/:id", getUser) -e.Put("/users/:id", updateUser) -e.Delete("/users/:id", deleteUser) +e.POST("/users", saveUser) +e.GET("/users/:id", getUser) +e.PUT("/users/:id", updateUser) +e.DELETE("/users/:id", deleteUser) ``` ### Path Parameters @@ -178,7 +178,7 @@ type User struct { Email string `json:"email" xml:"email"` } -e.Post("/users", func(c echo.Context) error { +e.POST("/users", func(c echo.Context) error { u := new(User) if err := c.Bind(u); err != nil { return err @@ -224,7 +224,7 @@ track := func(next echo.HandlerFunc) echo.HandlerFunc { return next(c) } } -e.Get("/users", func(c echo.Context) error { +e.GET("/users", func(c echo.Context) error { return c.String(http.StatusOK, "/users") }, track) ``` diff --git a/echo.go b/echo.go index ebad97e7..13514b35 100644 --- a/echo.go +++ b/echo.go @@ -27,7 +27,7 @@ Example: e.Use(middleware.Recover()) // Routes - e.Get("/", hello) + e.GET("/", hello) // Start server e.Run(standard.New(":1323")) @@ -318,8 +318,13 @@ func (e *Echo) Use(middleware ...MiddlewareFunc) { e.middleware = append(e.middleware, middleware...) } -// Connect registers a new CONNECT route for a path with matching handler in the +// CONNECT registers a new CONNECT route for a path with matching handler in the // router with optional route-level middleware. +func (e *Echo) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(CONNECT, path, h, m...) +} + +// Connect is deprecated, use `CONNECT()` instead. func (e *Echo) Connect(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(CONNECT, path, h, m...) } @@ -330,44 +335,79 @@ func (e *Echo) Delete(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(DELETE, path, h, m...) } -// Get registers a new GET route for a path with matching handler in the router +// GET registers a new GET route for a path with matching handler in the router // with optional route-level middleware. +func (e *Echo) GET(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(GET, path, h, m...) +} + +// Get is deprecated, use `GET()` instead. func (e *Echo) Get(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(GET, path, h, m...) } -// Head registers a new HEAD route for a path with matching handler in the +// HEAD registers a new HEAD route for a path with matching handler in the // router with optional route-level middleware. +func (e *Echo) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(HEAD, path, h, m...) +} + +// Head is deprecated, use `HEAD()` instead. func (e *Echo) Head(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(HEAD, path, h, m...) } -// Options registers a new OPTIONS route for a path with matching handler in the +// OPTIONS registers a new OPTIONS route for a path with matching handler in the // router with optional route-level middleware. +func (e *Echo) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(OPTIONS, path, h, m...) +} + +// Options is deprecated, use `OPTIONS()` instead. func (e *Echo) Options(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(OPTIONS, path, h, m...) } -// Patch registers a new PATCH route for a path with matching handler in the +// PATCH registers a new PATCH route for a path with matching handler in the // router with optional route-level middleware. +func (e *Echo) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(PATCH, path, h, m...) +} + +// Patch is deprecated, use `PATCH()` instead. func (e *Echo) Patch(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(PATCH, path, h, m...) } -// Post registers a new POST route for a path with matching handler in the +// POST registers a new POST route for a path with matching handler in the // router with optional route-level middleware. +func (e *Echo) POST(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(POST, path, h, m...) +} + +// Post is deprecated, use `POST()` instead. func (e *Echo) Post(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(POST, path, h, m...) } -// Put registers a new PUT route for a path with matching handler in the +// PUT registers a new PUT route for a path with matching handler in the // router with optional route-level middleware. +func (e *Echo) PUT(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(PUT, path, h, m...) +} + +// Put is deprecated, use `PUT()` instead. func (e *Echo) Put(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(PUT, path, h, m...) } -// Trace registers a new TRACE route for a path with matching handler in the +// TRACE registers a new TRACE route for a path with matching handler in the // router with optional route-level middleware. +func (e *Echo) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) { + e.add(TRACE, path, h, m...) +} + +// Trace is deprecated, use `TRACE()` instead. func (e *Echo) Trace(path string, h HandlerFunc, m ...MiddlewareFunc) { e.add(TRACE, path, h, m...) } @@ -391,14 +431,14 @@ func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middlew // Static registers a new route with path prefix to serve static files from the // provided root directory. func (e *Echo) Static(prefix, root string) { - e.Get(prefix+"*", func(c Context) error { + e.GET(prefix+"*", func(c Context) error { return c.File(path.Join(root, c.P(0))) }) } // File registers a new route with path to serve a static file. func (e *Echo) File(path, file string) { - e.Get(path, func(c Context) error { + e.GET(path, func(c Context) error { return c.File(file) }) } diff --git a/echo_test.go b/echo_test.go index d87c2dc4..4d5d4364 100644 --- a/echo_test.go +++ b/echo_test.go @@ -105,7 +105,7 @@ func TestEchoMiddleware(t *testing.T) { })) // Route - e.Get("/", func(c Context) error { + e.GET("/", func(c Context) error { return c.String(http.StatusOK, "OK") }) @@ -120,7 +120,7 @@ func TestEchoMiddlewareError(t *testing.T) { e.Use(WrapMiddleware(func(c Context) error { return errors.New("error") })) - e.Get("/", notFoundHandler) + e.GET("/", notFoundHandler) c, _ := request(GET, "/", e) assert.Equal(t, http.StatusInternalServerError, c) } @@ -129,7 +129,7 @@ func TestEchoHandler(t *testing.T) { e := New() // HandlerFunc - e.Get("/ok", func(c Context) error { + e.GET("/ok", func(c Context) error { return c.String(http.StatusOK, "OK") }) @@ -203,8 +203,8 @@ func TestEchoURL(t *testing.T) { getUser := func(Context) error { return nil } getFile := func(Context) error { return nil } - e.Get("/static/file", static) - e.Get("/users/:id", getUser) + e.GET("/static/file", static) + e.GET("/users/:id", getUser) g := e.Group("/group") g.Get("/users/:uid/files/:fid", getFile) @@ -252,7 +252,7 @@ func TestEchoGroup(t *testing.T) { // Routes //-------- - e.Get("/users", h) + e.GET("/users", h) // Group g1 := e.Group("/group1") @@ -297,7 +297,7 @@ func TestEchoNotFound(t *testing.T) { func TestEchoMethodNotAllowed(t *testing.T) { e := New() - e.Get("/", func(c Context) error { + e.GET("/", func(c Context) error { return c.String(http.StatusOK, "Echo!") }) rq := test.NewRequest(POST, "/", nil) diff --git a/group.go b/group.go index a20f1745..66706a8e 100644 --- a/group.go +++ b/group.go @@ -21,47 +21,92 @@ func (g *Group) Use(m ...MiddlewareFunc) { }, g.middleware...) } -// Connect implements `Echo#Connect()` for sub-routes within the Group. +// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group. +func (g *Group) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(CONNECT, path, h, m...) +} + +// Connect is deprecated, use `CONNECT()` instead. func (g *Group) Connect(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(CONNECT, path, h, m...) } -// Delete implements `Echo#Delete()` for sub-routes within the Group. +// DELETE implements `Echo#DELETE()` for sub-routes within the Group. +func (g *Group) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(DELETE, path, h, m...) +} + +// Delete is deprecated, use `DELETE()` instead. func (g *Group) Delete(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(DELETE, path, h, m...) } -// Get implements `Echo#Get()` for sub-routes within the Group. +// GET implements `Echo#GET()` for sub-routes within the Group. +func (g *Group) GET(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(GET, path, h, m...) +} + +// Get is deprecated, use `GET()` instead. func (g *Group) Get(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(GET, path, h, m...) } -// Head implements `Echo#Head()` for sub-routes within the Group. +// HEAD implements `Echo#HEAD()` for sub-routes within the Group. +func (g *Group) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(HEAD, path, h, m...) +} + +// Head is deprecated, use `HEAD()` instead. func (g *Group) Head(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(HEAD, path, h, m...) } -// Options implements `Echo#Options()` for sub-routes within the Group. +// OPTIONS implements `Echo#OPTIONS()` for sub-routes within the Group. +func (g *Group) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(OPTIONS, path, h, m...) +} + +// Options is deprecated, use `OPTIONS()` instead. func (g *Group) Options(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(OPTIONS, path, h, m...) } -// Patch implements `Echo#Patch()` for sub-routes within the Group. +// PATCH implements `Echo#PATCH()` for sub-routes within the Group. +func (g *Group) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(PATCH, path, h, m...) +} + +// Patch is deprecated, use `PATCH()` instead. func (g *Group) Patch(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(PATCH, path, h, m...) } -// Post implements `Echo#Post()` for sub-routes within the Group. +// POST implements `Echo#POST()` for sub-routes within the Group. +func (g *Group) POST(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(POST, path, h, m...) +} + +// Post is deprecated, use `POST()` instead. func (g *Group) Post(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(POST, path, h, m...) } -// Put implements `Echo#Put()` for sub-routes within the Group. +// PUT implements `Echo#PUT()` for sub-routes within the Group. +func (g *Group) PUT(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(PUT, path, h, m...) +} + +// Put is deprecated, use `PUT()` instead. func (g *Group) Put(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(PUT, path, h, m...) } -// Trace implements `Echo#Trace()` for sub-routes within the Group. +// TRACE implements `Echo#TRACE()` for sub-routes within the Group. +func (g *Group) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) { + g.add(TRACE, path, h, m...) +} + +// Trace is deprecated, use `TRACE()` instead. func (g *Group) Trace(path string, h HandlerFunc, m ...MiddlewareFunc) { g.add(TRACE, path, h, m...) } diff --git a/middleware/compress_test.go b/middleware/compress_test.go index c46d33d5..7d9d8242 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -65,7 +65,7 @@ func TestGzipNoContent(t *testing.T) { func TestGzipErrorReturned(t *testing.T) { e := echo.New() e.Use(Gzip()) - e.Get("/", func(c echo.Context) error { + e.GET("/", func(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, "error") }) rq := test.NewRequest(echo.GET, "/", nil)