Skip to content

Commit 022d3c7

Browse files
authored
Update Ctxt docs and What's new
1 parent 12daef3 commit 022d3c7

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

docs/api/ctx.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,20 @@ app.Get("/hello", func(c fiber.Ctx) error {
354354

355355
## Context
356356

357-
Returns [\*fasthttp.RequestCtx](https://godoc.org/github.com/valyala/fasthttp#RequestCtx) that is compatible with the context.Context interface that requires a deadline, a cancellation signal, and other values across API boundaries.
357+
Context returns a context implementation that was set by user earlier or returns a non-nil, empty context, if it was not set earlier.
358358

359359
```go title="Signature"
360-
func (c Ctx) Context() *fasthttp.RequestCtx
360+
func (c Ctx) Context() context.Context
361361
```
362362

363-
:::info
364-
Please read the [Fasthttp Documentation](https://pkg.go.dev/github.com/valyala/fasthttp?tab=doc) for more information.
365-
:::
363+
```go title="Example"
364+
app.Get("/", func(c fiber.Ctx) error {
365+
ctx := c.Context()
366+
// ctx is context implementation set by user
367+
368+
// ...
369+
})
370+
```
366371

367372
## Cookie
368373

@@ -1489,6 +1494,19 @@ app.Get("/", func(c fiber.Ctx) error {
14891494
})
14901495
```
14911496
1497+
## RequestCtx
1498+
1499+
Returns [\*fasthttp.RequestCtx](https://godoc.org/github.com/valyala/fasthttp#RequestCtx) that is compatible with the context.Context interface that requires a deadline, a cancellation signal, and other values across API boundaries.
1500+
1501+
```go title="Signature"
1502+
func (c Ctx) RequestCtx() *fasthttp.RequestCtx
1503+
```
1504+
1505+
:::info
1506+
Please read the [Fasthttp Documentation](https://pkg.go.dev/github.com/valyala/fasthttp?tab=doc) for more information.
1507+
:::
1508+
1509+
14921510
## Response
14931511
14941512
Response return the [\*fasthttp.Response](https://godoc.org/github.com/valyala/fasthttp#Response) pointer
@@ -1893,7 +1911,7 @@ app.Get("/", func(c fiber.Ctx) error {
18931911

18941912
## SetContext
18951913

1896-
Sets the user specified implementation for context interface.
1914+
Sets the user specified implementation for context.Context interface.
18971915

18981916
```go title="Signature"
18991917
func (c Ctx) SetContext(ctx context.Context)
@@ -2005,24 +2023,6 @@ app.Get("/", func(c fiber.Ctx) error {
20052023
})
20062024
```
20072025

2008-
## Context
2009-
2010-
Context returns a context implementation that was set by user earlier
2011-
or returns a non-nil, empty context, if it was not set earlier.
2012-
2013-
```go title="Signature"
2014-
func (c Ctx) Context() context.Context
2015-
```
2016-
2017-
```go title="Example"
2018-
app.Get("/", func(c fiber.Ctx) error {
2019-
ctx := c.Context()
2020-
// ctx is context implementation set by user
2021-
2022-
// ...
2023-
})
2024-
```
2025-
20262026
## Vary
20272027

20282028
Adds the given header field to the [Vary](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary) response header. This will append the header, if not already listed, otherwise leaves it listed in the current location.

docs/whats_new.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ DRAFT section
229229
- Format -> Param: body interface{} -> handlers ...ResFmt
230230
- Redirect -> c.Redirect().To()
231231
- SendFile now supports different configurations using the config parameter.
232+
- Context has been renamed to RequestCtx which corresponds to the FastHTTP Request Context.
233+
- UserContext has been renamed to Context which returns a context.Context object.
234+
- SetUserContext has been renamed to SetContext.
232235

233236
---
234237

0 commit comments

Comments
 (0)