Documentation
¶
Index ¶
- Constants
- Variables
- func New(config ...Config) fiber.Handler
- type Config
- type PageInfo
- func (p *PageInfo) CursorValues() map[string]any
- func (p *PageInfo) NextCursorURL(baseURL string) string
- func (p *PageInfo) NextPageURL(baseURL string) string
- func (p *PageInfo) PreviousPageURL(baseURL string) string
- func (p *PageInfo) SetNextCursor(values map[string]any) *PageInfo
- func (p *PageInfo) SortBy(field string, order SortOrder) *PageInfo
- func (p *PageInfo) Start() int
- type SortField
- type SortOrder
Constants ¶
const MaxLimit = 100
MaxLimit is the maximum limit allowed.
Variables ¶
var ConfigDefault = Config{ Next: nil, PageKey: "page", DefaultPage: 1, LimitKey: "limit", DefaultLimit: 10, CursorKey: "cursor", }
ConfigDefault is the default config.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Next defines a function to skip this middleware when returned true.
Next func(c fiber.Ctx) bool
// PageKey is the query string key for page number.
PageKey string
// DefaultPage is the default page number.
DefaultPage int
// LimitKey is the query string key for limit.
LimitKey string
// DefaultLimit is the default items per page.
DefaultLimit int
// SortKey is the query string key for sort.
SortKey string
// DefaultSort is the default sort field.
DefaultSort string
// AllowedSorts is the list of allowed sort fields.
AllowedSorts []string
// CursorKey is the query string key for cursor-based pagination.
CursorKey string
// CursorParam is an optional alias for the cursor query key.
CursorParam string
}
Config defines the config for the pagination middleware.
type PageInfo ¶
type PageInfo struct {
Page int `json:"page"`
Limit int `json:"limit"`
Offset int `json:"offset"`
Sort []SortField `json:"sort"`
Cursor string `json:"cursor,omitempty"`
HasMore bool `json:"has_more,omitempty"`
NextCursor string `json:"next_cursor,omitempty"`
}
PageInfo contains pagination information.
func FromContext ¶
FromContext returns the PageInfo from the context.
func NewPageInfo ¶
NewPageInfo creates a new PageInfo.
func (*PageInfo) CursorValues ¶ added in v1.1.0
CursorValues decodes the opaque cursor into a key-value map. Returns nil if cursor is empty or invalid.
func (*PageInfo) NextCursorURL ¶ added in v1.1.0
NextCursorURL returns the URL for the next cursor page. Returns empty string if HasMore is false.
func (*PageInfo) NextPageURL ¶
NextPageURL returns the URL for the next page.
func (*PageInfo) PreviousPageURL ¶
PreviousPageURL returns the URL for the previous page. Returns empty string if on page 1.
func (*PageInfo) SetNextCursor ¶ added in v1.1.0
SetNextCursor encodes a key-value map into an opaque cursor token and sets both NextCursor and HasMore on the PageInfo. Chainable.