-
-
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
🤔 Dynamically Remove Routes #600
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Hi @Zeedinstein, our private We could add a safe method like func main() {
app := fiber.New()
tmp := app.Get("/", func(c *fiber.Ctx) {
c.Send("I'm reserved for 1 request 😭")
c.Route().Remove()
})
app.Get("/remove", func(c *fiber.Ctx) {
tmp.Remove()
})
log.Fatal(app.Listen(3000))
} |
Yeah looking at the source code I can see why it's complicated. You would probably have to rebuild the app's stack array. |
Here is the code I tried to get working(It's probably not the best code to do this):
This passes this test:
But fails for this test:
So it updates the |
Thanks for your suggestion @Zeedinstein . Removing routes dynamically will effect requests which are matching. That’ll cost a lot to ensure data security and consistency. Let us know whether the issue is resolved! |
I have to agree with @kiyonlin, I don't think a web framework should solve dynamic problems like this. A better approach would be to have an one catch all handler and lookup the user registered paths and respond accordingly. It would achieve the same results but with faster response time, because if the route is removed from the stack it would loop trough all routes looking for a match on each request resulting in a slower I hope this answered your question, feel free to close this issue 👍 |
I would like to see a real-world use case of deleting routes dynamically |
Instead of removing it is possible to overwrite the handler? Like Iris |
Modular routes, boom big use case |
Is there a way to dynamically remove routes from
fiber.App
or afiber.Group
, so that the route can not be accessed anymore and removed from memory. This is something I could do in express by accessing theapp.stack
which was just an array of the configured routes.I see in fiber I can get all the configured routes using
app.Routes()
but I don't have access toapp.stack
Is this possible to do with fiber?
The text was updated successfully, but these errors were encountered: