Cookie

Set cookie

  1. func (c *Ctx) Cookie(cookie *Cookie)
  1. type Cookie struct {
  2. Name string `json:"name"`
  3. Value string `json:"value"`
  4. Path string `json:"path"`
  5. Domain string `json:"domain"`
  6. MaxAge int `json:"max_age"`
  7. Expires time.Time `json:"expires"`
  8. Secure bool `json:"secure"`
  9. HTTPOnly bool `json:"http_only"`
  10. SameSite string `json:"same_site"`
  11. }
  1. app.Get("/", func(c *fiber.Ctx) error {
  2. // Create cookie
  3. cookie := new(fiber.Cookie)
  4. cookie.Name = "john"
  5. cookie.Value = "doe"
  6. cookie.Expires = time.Now().Add(24 * time.Hour)
  7. // Set cookie
  8. c.Cookie(cookie)
  9. // ...
  10. })