pagination

package
v0.0.0-...-9a2df54 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SettingsCursorSeperator = ":"
	ErrCursorInvalid        = fmt.Errorf("invalid cursor: should be 'direction%sindex'", SettingsCursorSeperator)
	ErrDirectionInvalid     = fmt.Errorf("invalid direction: should be 'next' or 'prev'")
)

Functions

func EncodeCursor

func EncodeCursor(cursor string, direction Direction) string

Types

type Cursor

type Cursor struct {
	Total       int
	HasPrevPage bool
	HasNextPage bool
	Start       any
	End         any
}

Cursor holds pointers to the first and last items on a page.

func NewCursor

func NewCursor[Records any](entries []Records, isFirstPage bool, limit int, cursorStructField string) (Cursor, []Records)

type Direction

type Direction string
const (
	DirectionNext Direction = "next"
	DirectionPrev Direction = "prev"
)

func DecodeCursor

func DecodeCursor(pageCursor string) (dir Direction, cursor string, err error)

func (Direction) IsValid

func (d Direction) IsValid() bool

func (Direction) String

func (d Direction) String() string

Jump to

Keyboard shortcuts

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