1
0
mirror of https://github.com/labstack/echo.git synced 2025-11-06 08:59:21 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-11-22 10:38:02 -08:00
parent 2ad06ce67e
commit 9d11990cbb
3 changed files with 33 additions and 5 deletions

View File

@@ -8,7 +8,8 @@ menu:
### Handler path
`Context.Path()` returns the registered path for a handler, it can be used in the middleware for logging purpose.
`Context#Path()` returns the registered path for a handler, it can be used in the
middleware for logging purpose.
*Example*
@@ -22,10 +23,27 @@ e.Get("/users/:name", func(c *echo.Context) error) {
})
```
### golang.org/x/net/context
`echo.Context` embeds `context.Context` interface, so all it's properties
are available right from `echo.Context`.
*Example*
```go
e.Get("/users/:name", func(c *echo.Context) error) {
c.Context = context.WithValue(nil, "key", "val")
// Pass it down...
// Use it...
println(c.Value("key"))
return c.String(http.StatusOK, name)
})
```
### Path parameter
Path parameter can be retrieved either by name `Context.Param(name string) string`
or by index `Context.P(i int) string`. Getting parameter by index gives a slightly
Path parameter can be retrieved either by name `Context#Param(name string) string`
or by index `Context#P(i int) string`. Getting parameter by index gives a slightly
better performance.
*Example*
@@ -48,7 +66,7 @@ $ curl http://localhost:1323/users/joe
### Query parameter
Query parameter can be retrieved by name using `Context.Query(name string)`.
Query parameter can be retrieved by name using `Context#Query(name string)`.
*Example*
@@ -65,7 +83,7 @@ $ curl -G -d "name=joe" http://localhost:1323/users
### Form parameter
Form parameter can be retrieved by name using `Context.Form(name string)`.
Form parameter can be retrieved by name using `Context#Form(name string)`.
*Example*