FromCookie creates an Extractor that retrieves a value from a specified cookie in the request. The function: - Retrieves the cookie value using the specified name - Returns ErrNotFound if the cookie is missing Parameters: - key: The name of the cookie from which to extract the value. Returns: A
(key string)
| 218 | // // Cookie: "session_id=abc123" -> Output: "abc123" |
| 219 | // // Missing cookie -> Output: ErrNotFound |
| 220 | func FromCookie(key string) Extractor { |
| 221 | return Extractor{ |
| 222 | Extract: func(c fiber.Ctx) (string, error) { |
| 223 | value := c.Cookies(key) |
| 224 | if value == "" { |
| 225 | return "", ErrNotFound |
| 226 | } |
| 227 | return value, nil |
| 228 | }, |
| 229 | Key: key, |
| 230 | Source: SourceCookie, |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // FromParam creates an Extractor that retrieves a value from a specified URL parameter in the request. |
| 235 | // URL parameters are extracted from the route path (e.g., /users/:id). |