-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥 feat: Add Support for Removing Routes (#3230)
* Add new methods named RemoveRoute and RemoveRouteByName. * Update register method to prevent duplicate routes. * Clean up tests * Update docs
- Loading branch information
Showing
4 changed files
with
392 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -761,3 +761,56 @@ func main() { | |
``` | ||
|
||
In this example, a new route is defined and then `RebuildTree()` is called to ensure the new route is registered and available. | ||
|
||
|
||
Check failure on line 765 in docs/api/app.md GitHub Actions / markdownlintMultiple consecutive blank lines
|
||
## RemoveRoute | ||
|
||
This method removes a route by path. You must call the `RebuildTree()` method after the remove in to ensure the route is removed. | ||
|
||
```go title="Signature" | ||
func (app *App) RemoveRoute(path string, methods ...string) | ||
``` | ||
|
||
This method removes a route by name | ||
```go title="Signature" | ||
Check failure on line 775 in docs/api/app.md GitHub Actions / markdownlintFenced code blocks should be surrounded by blank lines
|
||
func (app *App) RemoveRouteByName(name string, methods ...string) | ||
``` | ||
|
||
```go title="Example" | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gofiber/fiber/v3" | ||
) | ||
|
||
func main() { | ||
app := fiber.New() | ||
|
||
app.Get("/api/feature-a", func(c *fiber.Ctx) error { | ||
app.RemoveRoute("/api/feature", fiber.MethodGet) | ||
app.RebuildTree() | ||
// Redefine route | ||
app.Get("/api/feature", func(c *fiber.Ctx) error { | ||
return c.SendString("Testing feature-a") | ||
}) | ||
|
||
app.RebuildTree() | ||
return c.SendStatus(fiber.StatusOK) | ||
}) | ||
app.Get("/api/feature-b", func(c *fiber.Ctx) error { | ||
app.RemoveRoute("/api/feature", fiber.MethodGet) | ||
app.RebuildTree() | ||
// Redefine route | ||
app.Get("/api/feature", func(c *fiber.Ctx) error { | ||
return c.SendString("Testing feature-b") | ||
}) | ||
|
||
app.RebuildTree() | ||
return c.SendStatus(fiber.StatusOK) | ||
}) | ||
|
||
log.Fatal(app.Listen(":3000")) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.