Skip to content

Commit 1c2ac6a

Browse files
committed
add docs
1 parent a91c40d commit 1c2ac6a

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

Diff for: docs/api/ctx.md

+23-6
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,40 @@ app.Post("/", func(c fiber.Ctx) error {
4141
})
4242
```
4343

44-
### Context
44+
## Context
4545

46-
`Context` returns a context implementation that was set by the user earlier or returns a non-nil, empty context if it was not set earlier.
46+
`Context` implements `context.Context`. However due to [current limitations in how fasthttp](https://github.com/valyala/fasthttp/issues/965#issuecomment-777268945) works, `Deadline()`, `Done()` and `Err()` operate as a nop.
4747

4848
```go title="Signature"
49-
func (c fiber.Ctx) Context() context.Context
49+
func (c fiber.Ctx) Deadline() (deadline time.Time, ok bool)
50+
func (c fiber.Ctx) Done() <-chan struct{}
51+
func (c fiber.Ctx) Err() error
52+
func (c fiber.Ctx) Value(key any) any
5053
```
5154

5255
```go title="Example"
53-
app.Get("/", func(c fiber.Ctx) error {
54-
ctx := c.Context()
55-
// ctx is context implementation set by user
5656

57+
func doSomething(ctx context.Context) {
5758
// ...
59+
}
60+
61+
app.Get("/", func(c fiber.Ctx) error {
62+
doSomething(c)
63+
})
64+
```
65+
66+
### Value
67+
68+
Value can be used to retrieve [**`Locals`**](./#locals).
69+
70+
```go title="Example"
71+
app.Get("/", func(c fiber.Ctx) error {
72+
c.Locals(userKey, "admin")
73+
user := c.Value(userKey) // returns "admin"
5874
})
5975
```
6076

77+
6178
### Drop
6279

6380
Terminates the client connection silently without sending any HTTP headers or response body.

0 commit comments

Comments
 (0)