paging

package
v0.1.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCursor = fmt.Errorf("invalid cursor")
)

Functions

func DecodeCursor

func DecodeCursor(cursor string) (string, int64, error)

func EncodeCursor

func EncodeCursor(value string) string

Types

type CursorProvider

type CursorProvider interface {
	GetCursorValue() string
}

type PagingFunc

type PagingFunc[T CursorProvider] func(cursor string, limit int, direction string) (items []T, total int, err error)

type Params

type Params struct {
	Cursor    string `json:"cursor"`
	Limit     int    `json:"limit"`
	Direction string `json:"direction"` // "forward" or "backward"
}

func NormalizeParams

func NormalizeParams(params Params) Params

type Result

type Result[T CursorProvider] struct {
	Items      []T    `json:"items"`
	Total      int    `json:"total"`
	Cursor     string `json:"cursor,omitempty"`
	NextCursor string `json:"next_cursor,omitempty"`
	PrevCursor string `json:"prev_cursor,omitempty"`
	HasNext    bool   `json:"has_next"`
	HasPrev    bool   `json:"has_prev"`
}

func Paginate

func Paginate[T CursorProvider](params Params, paginateFunc PagingFunc[T]) (Result[T], error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL