paging

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 31, 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"`
	HasNextPage bool   `json:"has_next_page"`
	HasPrevPage bool   `json:"has_prev_page"`
}

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