-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add context.Context Support to Additional Middlewares #3212
Comments
code from the request id middleware adjustement |
@ReneWerner87 We need to carefully discuss which middleware need to add requestID, because from the routing to the control layer to the service layer in this process, I see that most of the Go developers will choose to control layer Fiber's Ctx into UserContext, because Fiber as a web framework its function in the whole architecture in the control layer has ended, the service layer will be conducted specific business processing, in the service layer business more concurrent security context, and fiber context is not concurrent security, and requestId in the microservice link tracking is very important to locate the problem, so here will be proposed to increase the request mw UserContext requestID. The following is the GPT's answer for reference.
Example of what to avoid. app.Get(“/”, func(c *fiber.Ctx) error {
go func() {
// UNSAFE: accessing ctx from different goroutine
data := c.Query(“someData”)
}()
return nil
}) Safe approach. app.Get(“/”, func(c *fiber.Ctx) error {
data := c.Query(“someData”) // Get data first
go func(safeData string) {
// SAFE: using copied data
process(safeData)
}(data)
return nil
}) |
@JIeJaitt This is for using |
Based on the discussion in Issue #3175, we need to extend context support to other middlewares for consistency.
Middlewares to update:
This will ensure that relevant context can be passed through the
context.Context
in these middlewares.Requester: @ReneWerner87
The text was updated successfully, but these errors were encountered: