mirror of
https://github.com/labstack/echo.git
synced 2025-11-06 08:59:21 +02:00
Added X() method to return context
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
e.Use(func(c *echo.Context) error {
|
||||
e.Use(func(c echo.Context) error {
|
||||
// Extract the credentials from HTTP request header and perform a security
|
||||
// check
|
||||
|
||||
@@ -40,7 +40,7 @@ func main() {
|
||||
e.Run(":1323")
|
||||
}
|
||||
|
||||
func welcome(c *echo.Context) error {
|
||||
func welcome(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "Welcome!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -14,11 +14,11 @@ middleware for logging purpose.
|
||||
*Example*
|
||||
|
||||
```go
|
||||
e.Use(func(c *echo.Context) error {
|
||||
e.Use(func(c echo.Context) error {
|
||||
println(c.Path()) // Prints `/users/:name`
|
||||
return nil
|
||||
})
|
||||
e.Get("/users/:name", func(c *echo.Context) error) {
|
||||
e.Get("/users/:name", func(c echo.Context) error) {
|
||||
return c.String(http.StatusOK, name)
|
||||
})
|
||||
```
|
||||
@@ -31,7 +31,7 @@ are available right from `echo.Context`.
|
||||
*Example*
|
||||
|
||||
```go
|
||||
e.Get("/users/:name", func(c *echo.Context) error) {
|
||||
e.Get("/users/:name", func(c echo.Context) error) {
|
||||
c.Context = context.WithValue(nil, "key", "val")
|
||||
// Pass it down...
|
||||
// Use it...
|
||||
@@ -49,7 +49,7 @@ better performance.
|
||||
*Example*
|
||||
|
||||
```go
|
||||
e.Get("/users/:name", func(c *echo.Context) error {
|
||||
e.Get("/users/:name", func(c echo.Context) error {
|
||||
// By name
|
||||
name := c.Param("name")
|
||||
|
||||
@@ -71,7 +71,7 @@ Query parameter can be retrieved by name using `Context#Query(name string)`.
|
||||
*Example*
|
||||
|
||||
```go
|
||||
e.Get("/users", func(c *echo.Context) error {
|
||||
e.Get("/users", func(c echo.Context) error {
|
||||
name := c.Query("name")
|
||||
return c.String(http.StatusOK, name)
|
||||
})
|
||||
@@ -88,7 +88,7 @@ Form parameter can be retrieved by name using `Context#Form(name string)`.
|
||||
*Example*
|
||||
|
||||
```go
|
||||
e.Post("/users", func(c *echo.Context) error {
|
||||
e.Post("/users", func(c echo.Context) error {
|
||||
name := c.Form("name")
|
||||
return c.String(http.StatusOK, name)
|
||||
})
|
||||
|
||||
@@ -53,7 +53,7 @@ e.Get("/hello", Hello)
|
||||
- Render template
|
||||
|
||||
```go
|
||||
func Hello(c *echo.Context) error {
|
||||
func Hello(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "hello", "World")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -16,7 +16,7 @@ code below registers a route for method `GET`, path `/hello` and a handler which
|
||||
`Hello!` HTTP response.
|
||||
|
||||
```go
|
||||
e.Get("/hello", func(c *echo.Context) error {
|
||||
e.Get("/hello", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "Hello!")
|
||||
})
|
||||
```
|
||||
@@ -48,15 +48,15 @@ match:
|
||||
#### Example
|
||||
|
||||
```go
|
||||
e.Get("/users/:id", func(c *echo.Context) error {
|
||||
e.Get("/users/:id", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "/users/:id")
|
||||
})
|
||||
|
||||
e.Get("/users/new", func(c *echo.Context) error {
|
||||
e.Get("/users/new", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "/users/new")
|
||||
})
|
||||
|
||||
e.Get("/users/1/files/*", func(c *echo.Context) error {
|
||||
e.Get("/users/1/files/*", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "/users/1/files/*")
|
||||
})
|
||||
```
|
||||
@@ -101,7 +101,7 @@ application.
|
||||
|
||||
```go
|
||||
// Handler
|
||||
h := func(c *echo.Context) error {
|
||||
h := func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "OK")
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ import (
|
||||
)
|
||||
|
||||
// Handler
|
||||
func hello(c *echo.Context) error {
|
||||
func hello(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "Hello, World!\n")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user