Skip to content

Commit 9d11990

Browse files
committed
Closes #104
Signed-off-by: Vishal Rana <[email protected]>
1 parent 2ad06ce commit 9d11990

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212

1313
"bytes"
1414

15+
"golang.org/x/net/context"
1516
"golang.org/x/net/websocket"
1617
)
1718

1819
type (
1920
// Context represents context for the current request. It holds request and
2021
// response objects, path parameters, data and registered handler.
2122
Context struct {
23+
context.Context
2224
request *http.Request
2325
response *Response
2426
socket *websocket.Conn

context_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"strings"
1212

13+
"golang.org/x/net/context"
14+
1315
"net/url"
1416

1517
"encoding/xml"
@@ -271,6 +273,12 @@ func TestContextForm(t *testing.T) {
271273
assert.Equal(t, "[email protected]", c.Form("email"))
272274
}
273275

276+
func TestContextNetContext(t *testing.T) {
277+
c := new(Context)
278+
c.Context = context.WithValue(nil, "key", "val")
279+
assert.Equal(t, "val", c.Value("key"))
280+
}
281+
274282
func testBind(t *testing.T, c *Context, ct string) {
275283
c.request.Header.Set(ContentType, ct)
276284
u := new(user)

website/content/guide/request.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ menu:
88

99
### Handler path
1010

11-
`Context.Path()` returns the registered path for a handler, it can be used in the middleware for logging purpose.
11+
`Context#Path()` returns the registered path for a handler, it can be used in the
12+
middleware for logging purpose.
1213

1314
*Example*
1415

@@ -22,10 +23,27 @@ e.Get("/users/:name", func(c *echo.Context) error) {
2223
})
2324
```
2425

26+
### golang.org/x/net/context
27+
28+
`echo.Context` embeds `context.Context` interface, so all it's properties
29+
are available right from `echo.Context`.
30+
31+
*Example*
32+
33+
```go
34+
e.Get("/users/:name", func(c *echo.Context) error) {
35+
c.Context = context.WithValue(nil, "key", "val")
36+
// Pass it down...
37+
// Use it...
38+
println(c.Value("key"))
39+
return c.String(http.StatusOK, name)
40+
})
41+
```
42+
2543
### Path parameter
2644

27-
Path parameter can be retrieved either by name `Context.Param(name string) string`
28-
or by index `Context.P(i int) string`. Getting parameter by index gives a slightly
45+
Path parameter can be retrieved either by name `Context#Param(name string) string`
46+
or by index `Context#P(i int) string`. Getting parameter by index gives a slightly
2947
better performance.
3048

3149
*Example*
@@ -48,7 +66,7 @@ $ curl http://localhost:1323/users/joe
4866

4967
### Query parameter
5068

51-
Query parameter can be retrieved by name using `Context.Query(name string)`.
69+
Query parameter can be retrieved by name using `Context#Query(name string)`.
5270

5371
*Example*
5472

@@ -65,7 +83,7 @@ $ curl -G -d "name=joe" http://localhost:1323/users
6583

6684
### Form parameter
6785

68-
Form parameter can be retrieved by name using `Context.Form(name string)`.
86+
Form parameter can be retrieved by name using `Context#Form(name string)`.
6987

7088
*Example*
7189

0 commit comments

Comments
 (0)