-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement context.Context in App.Ctx. #383
Conversation
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Someone please fix the failed github workflow file. |
@boolooper thank you for your first PR, Fiber supports getting/setting context values using ctx.Locals(). Please take a minute to read our documentation https://docs.gofiber.io or visit our examples https://github.com/gofiber/recipes. In these docs you can also find the |
This PR does not only adds "passing context values". It's about implementing the The goal of this PR is supporting App.Ctx for passing as a parameter to functions line sql.Conn.BeginTx.
|
Thanks for your proposal and use-case example. Fiber almost implements an one on one expressjs like API. We are open for improvements/features to be added to the Ctx. I'm not sure if it's worth to add the context.Context interface directly to the Fiber Ctx. In the end Fiber is a simplified layer build around Fasthttp, so if you really need to pass a context interface you could use ctx.Fasthttp (fasthttp.RequestCtx). app.Get("/", func(c *fiber.Ctx) {
db.QueryContext(c.Fasthttp, "SELECT name FROM users WHERE age=?", 25)
}) My main concern is that if we add Feel free to share your thoughts, I will leave this PR open for discussion and invite the @gofiber/maintainers to join! Feel free to chat with us on discord https://gofiber.io/discord |
Just saw, |
// express
app.get('/user/:id', function (req, res) {
res.write('<html>');
res.write('<body>');
res.write('<h1>Hello, World!</h1>');
res.write('</body>');
res.write('</html>');
res.end()
}); // fiber
app.Get("/user/:id", func(ctx *fiber.Ctx) {
ctx.Write("<html>");
ctx.Write("<body>");
ctx.Write("<h1>Hello, World!</h1>");
ctx.Write("</body>");
ctx.Write("</html>");
}); I'm closing this PR for now since an alternative solution is provided #383 (comment) |
But I would really request you to provide a function like Moving from fasthttp to fiber is making my code look weird for this silly reason. Best regards. |
You got a valid point, if the @gofiber/maintainers agree we could merge it if a test case is also provided. |
@gofiber/maintainers LGTM, I would like to see this merged in |
Added in v1.10.0 under |
context.Context
- https://godoc.org/context#ContextError string format - https://github.com/golang/go/wiki/CodeReviewComments#error-strings