πŸͺ
Hooks
With Fiber v2.30.0, you can execute custom user functions when to run some methods. Here is a list of this hooks:

Constants

// Handlers define a function to create hooks for Fiber.
type OnRouteHandler = func(Route) error
type OnNameHandler = OnRouteHandler
type OnGroupHandler = func(Group) error
type OnGroupNameHandler = OnGroupHandler
type OnListenHandler = func() error
type OnForkHandler = func(int) error
type OnShutdownHandler = OnListenHandler

OnRoute

OnRoute is a hook to execute user functions on each route registeration. Also you can get route properties by route parameter.
Signature
func (app *App) OnRoute(handler ...OnRouteHandler)

OnName

OnName is a hook to execute user functions on each route naming. Also you can get route properties by route parameter.
WARN: OnName only works with naming routes, not groups.
Signature
func (app *App) OnName(handler ...OnNameHandler)
OnName Example
package main
​
import (
"fmt"
​
"github.com/gofiber/fiber/v2"
)
​
func main() {
app := fiber.New()
​
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString(c.Route().Name)
}).Name("index")
​
app.Hooks().OnName(func(r fiber.Route) error {
fmt.Print("Name: " + r.Name + ", ")
​
return nil
})
​
app.Hooks().OnName(func(r fiber.Route) error {
fmt.Print("Method: " + r.Method + "\n")
​
return nil
})
​
app.Get("/add/user", func(c *fiber.Ctx) error {
return c.SendString(c.Route().Name)
}).Name("addUser")
​
app.Delete("/destroy/user", func(c *fiber.Ctx) error {
return c.SendString(c.Route().Name)
}).Name("destroyUser")
​
app.Listen(":5000")
}
​
// Results:
// Name: addUser, Method: GET
// Name: destroyUser, Method: DELETE

OnGroup

OnGroup is a hook to execute user functions on each group registeration. Also you can get group properties by group parameter.
Signature
func (app *App) OnGroup(handler ...OnGroupHandler)

OnGroupName

OnGroupName is a hook to execute user functions on each group naming. Also you can get group properties by group parameter.
WARN: OnGroupName only works with naming groups, not routes.
Signature
func (app *App) OnGroupName(handler ...OnGroupNameHandler)

OnListen

OnListen is a hook to execute user functions on Listen, ListenTLS, Listener.
Signature
func (app *App) OnListen(handler ...OnListenHandler)

OnFork

OnFork is a hook to execute user functions on Fork.
Signature
func (app *App) OnFork(handler ...OnForkHandler)

OnShutdown

OnShutdown is a hook to execute user functions after Shutdown.
Signature
func (app *App) OnShutdown(handler ...OnShutdownHandler)