I am currently working on a project which requires HTTP-Routes being distributed over several plugins. Currently fiber is the used framework, a switch to another framework is possible if need be. The project is structured like this:
base
|
-- main
| | base-routes.go
|
--plugins
| |
| Plugin1
| | plugin1-routes.go
| | further files omitted
| |
| Plugin2
| | plugin2-routes.go
| |
Is there a chance of dynamically adding the routes depending on the installed plugins?
It would be perfect that after calling go run base.go --plugins=plugin1
all the routes and only these routes are added to the main routes. On calling go run base.go --plugins=plugin1,plugin2
all the routes should be established.
CodePudding user response:
With Fiber and with other web frameworks as Echo, Gin, ... you can add routes conditionally just with if
statements.
Initialization in Fiber looks like this (https://github.com/gofiber/fiber#️-quickstart):
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World