Like Routing, groups can also have paths that belong to a cluster.
func main() {app := fiber.New()api := app.Group("/api", middleware) // /apiv1 := api.Group("/v1", middleware) // /api/v1v1.Get("/list", handler) // /api/v1/listv1.Get("/user", handler) // /api/v1/userv2 := api.Group("/v2", middleware) // /api/v2v2.Get("/list", handler) // /api/v2/listv2.Get("/user", handler) // /api/v2/userapp.Listen(":3000")}
A Group of paths can have an optional handler.
func main() {app := fiber.New()api := app.Group("/api") // /apiv1 := api.Group("/v1") // /api/v1v1.Get("/list", handler) // /api/v1/listv1.Get("/user", handler) // /api/v1/userv2 := api.Group("/v2") // /api/v2v2.Get("/list", handler) // /api/v2/listv2.Get("/user", handler) // /api/v2/userapp.Listen(":3000")}
Running /api, /v1 or /v2 will result in 404 error, make sure you have the errors set.
Group handlers can also be used as a routing path but they must have Next added to them so that the flow can continue.
func main() {app := fiber.New()api := app.Group("/api") // /apiv1 := api.Group("/v1", func(c *fiber.Ctx) error {c.JSON(fiber.Map{"message": "v1",})return c.Next()}) // /api/v1v1.Get("/list", handler) // /api/v1/listv1.Get("/user", handler) // /api/v1/userapp.Listen(":3000")}