Locals

A method that stores variables scoped to the request and, therefore, are available only to the routes that match the request.

This is useful if you want to pass some specific data to the next middleware.
  1. func (c *Ctx) Locals(key string, value ...interface{}) interface{}
  1. app.Use(func(c *fiber.Ctx) error {
  2. c.Locals("user", "admin")
  3. return c.Next()
  4. })
  5. app.Get("/admin", func(c *fiber.Ctx) error {
  6. if c.Locals("user") == "admin" {
  7. return c.Status(200).SendString("Welcome, admin!")
  8. }
  9. return c.SendStatus(403)
  10. })