-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
📝 [Proposal]: Make fiber.Ctx implement context.Context #3344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@pjebs I kind of agree with this. We will discuss it internally. |
@pjebs Although it is tempting to unify them, implementing the full
|
That's how any context should be in a Request-Response cycle.
Currently that is already documented: https://docs.gofiber.io/#zero-allocation and already applies anyway with the current Ctx.
Currently if someone starts a goroutine that is expected to live longer than the request-response cycle, they are already expected to abide by the rules of using Fiber. If they want to use a goroutine that outlives the Fiber request-response cycle, they should create a
Yes this is true. But it can be created only once and never closed. It can be reused and documented what the rules are of using it. Most likely, people will use it to store values anyway. type fiber.Ctx interface {
Context() context.Context <============
SetContext(ctx context.Context) <============ |
type context.Context interface {
Deadline() (deadline time.Time, ok bool)
Done() <-chan struct{}
Err() error
Value(key any)any
} Here is an example of how to simply implement
|
@pjebs The fasthttp context already implements the functions from #3382 See:
|
Yes, but the aim is for fiber.Ctx to implement context.Context. |
Relevant valyala/fasthttp#1998 |
Feature Proposal Description
Having too many different types of contexts is confusing - especially for new people transitioning from other languages to Go. If it's going to be simplified, now is the time to do it.
Why not just make fiber.Ctx implement context.Context?
Currently,
fiber.Ctx.Context() context.Context
andfiber.Ctx.SetContext(ctx context.Context)
do nothing but store a user's customcontext.Context
into fasthttp's uservalues.Originally the signature of fasthttp's uservalues only accepted strings. I changed it to anything: https://github.com/valyala/fasthttp/pull/1387/files but the purpose wasn't to dump a custom context.Context into it at the expense of added confusion of another type of context.
If the user wants to pass custom values around from middleware to middleware etc, they can directly store it in fasthttp's request's user values OR even better, we make fiber.Ctx implement context.Context and allow them to store it in there.
Alignment with Express API
N/A
HTTP RFC Standards Compliance
N/A
API Stability
Not backward compatible with v2
Feature Examples
Checklist:
The text was updated successfully, but these errors were encountered: