description |
---|
List of frequently asked questions. Feel free to open an issue to add your question to this page. |
There is no definitive answer to this question. The answer depends on the scale of your application and the team that is involved. To be as flexible as possible, Fiber makes no assumptions in terms of structure.
Routes and other application-specific logic can live in as many files as you wish, in any directory structure you prefer. View the following examples for inspiration:
- gofiber/boilerplate
- thomasvvugt/fiber-boilerplate
- Youtube - Building a REST API using Gorm and Fiber
- embedmode/fiberseed
If you're using v2.32.0 or later, all you need to do is to implement a custom error handler. See below, or see a more detailed explanation at Error Handling.
If you're using v2.31.0 or earlier, the error handler will not capture 404 errors. Instead, you need to add a middleware function at the very bottom of the stack (below all other functions) to handle a 404 response:
{% code title="Example" %}
app.Use(func(c *fiber.Ctx) error {
return c.Status(fiber.StatusNotFound).SendString("Sorry can't find that!")
})
{% endcode %}
To override the default error handler, you can override the default when providing a Config when initiating a new Fiber instance.
{% code title="Example" %}
app := fiber.New(fiber.Config{
ErrorHandler: func(c *fiber.Ctx, err error) error {
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
},
})
{% endcode %}
We have a dedicated page explaining how error handling works in Fiber, see Error Handling.
Fiber currently supports 8 template engines in our gofiber/template middleware:
To learn more about using Templates in Fiber, see Templates.
Yes, we have our own Discord server, where we hang out. We have different rooms for every subject.
If you have questions or just want to have a chat, feel free to join us via this > invite link <.