OptionalPaginationParams returns the "page", "perPage", and "after" parameters from the request, or their default values if not present, "page" default is 1, "perPage" default is 30. In future, we may want to make the default values configurable, or even have this function returned from `withPaginat
(args map[string]any)
| 394 | // function returned from `withPagination`, where the defaults are provided alongside |
| 395 | // the min/max values. |
| 396 | func OptionalPaginationParams(args map[string]any) (PaginationParams, error) { |
| 397 | page, err := OptionalIntParamWithDefault(args, "page", 1) |
| 398 | if err != nil { |
| 399 | return PaginationParams{}, err |
| 400 | } |
| 401 | perPage, err := OptionalIntParamWithDefault(args, "perPage", 30) |
| 402 | if err != nil { |
| 403 | return PaginationParams{}, err |
| 404 | } |
| 405 | after, err := OptionalParam[string](args, "after") |
| 406 | if err != nil { |
| 407 | return PaginationParams{}, err |
| 408 | } |
| 409 | return PaginationParams{ |
| 410 | Page: page, |
| 411 | PerPage: perPage, |
| 412 | After: after, |
| 413 | }, nil |
| 414 | } |
| 415 | |
| 416 | // OptionalCursorPaginationParams returns the "perPage" and "after" parameters from the request, |
| 417 | // without the "page" parameter, suitable for cursor-based pagination only. |