From 022d3c79ca6546a29811456d43360f51c06a8de1 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:08:37 -0500 Subject: [PATCH] Update Ctxt docs and What's new --- docs/api/ctx.md | 48 +++++++++++++++++++++++------------------------ docs/whats_new.md | 3 +++ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/docs/api/ctx.md b/docs/api/ctx.md index 7ba14d053f..1073271431 100644 --- a/docs/api/ctx.md +++ b/docs/api/ctx.md @@ -354,15 +354,20 @@ app.Get("/hello", func(c fiber.Ctx) error { ## Context -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. +Context returns a context implementation that was set by user earlier or returns a non-nil, empty context, if it was not set earlier. ```go title="Signature" -func (c Ctx) Context() *fasthttp.RequestCtx +func (c Ctx) Context() context.Context ``` -:::info -Please read the [Fasthttp Documentation](https://pkg.go.dev/github.com/valyala/fasthttp?tab=doc) for more information. -::: +```go title="Example" +app.Get("/", func(c fiber.Ctx) error { + ctx := c.Context() + // ctx is context implementation set by user + + // ... +}) +``` ## Cookie @@ -1489,6 +1494,19 @@ app.Get("/", func(c fiber.Ctx) error { }) ``` +## RequestCtx + +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. + +```go title="Signature" +func (c Ctx) RequestCtx() *fasthttp.RequestCtx +``` + +:::info +Please read the [Fasthttp Documentation](https://pkg.go.dev/github.com/valyala/fasthttp?tab=doc) for more information. +::: + + ## Response 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 { ## SetContext -Sets the user specified implementation for context interface. +Sets the user specified implementation for context.Context interface. ```go title="Signature" func (c Ctx) SetContext(ctx context.Context) @@ -2005,24 +2023,6 @@ app.Get("/", func(c fiber.Ctx) error { }) ``` -## Context - -Context returns a context implementation that was set by user earlier -or returns a non-nil, empty context, if it was not set earlier. - -```go title="Signature" -func (c Ctx) Context() context.Context -``` - -```go title="Example" -app.Get("/", func(c fiber.Ctx) error { - ctx := c.Context() - // ctx is context implementation set by user - - // ... -}) -``` - ## Vary 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. diff --git a/docs/whats_new.md b/docs/whats_new.md index 540f82ad26..0a47dca491 100644 --- a/docs/whats_new.md +++ b/docs/whats_new.md @@ -229,6 +229,9 @@ DRAFT section - Format -> Param: body interface{} -> handlers ...ResFmt - Redirect -> c.Redirect().To() - SendFile now supports different configurations using the config parameter. +- Context has been renamed to RequestCtx which corresponds to the FastHTTP Request Context. +- UserContext has been renamed to Context which returns a context.Context object. +- SetUserContext has been renamed to SetContext. ---