pagination

package
v1.0.0-beta.201 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	Time time.Time
	ID   string
}

func DecodeCursor

func DecodeCursor(s string) (*Cursor, error)

DecodeCursor decodes a base64-encoded cursor string into a Cursor object.

func NewCursor

func NewCursor(t time.Time, id string) Cursor

NewCursor creates a new Cursor object with the given time and ID. The time is converted to UTC before being stored.

func (Cursor) Encode

func (c Cursor) Encode() string

Encode converts the cursor to a base64-encoded string representation. The encoded string is formatted as <RFC3339 time>,<ID>.

func (Cursor) MarshalText

func (c Cursor) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. It encodes the cursor into a text form.

func (*Cursor) UnmarshalText

func (c *Cursor) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. It decodes the cursor from its text form.

type Item

type Item interface {
	// Cursor returns the cursor used for cursor-based ordering
	Cursor() Cursor
}

Item is the interface that must be implemented by items used in cursor pagination. It provides access to the time and ID fields needed for cursor generation.

type Result

type Result[T any] struct {
	// The items returned
	Items []T `json:"items"`

	// Cursor for the next page
	NextCursor *string `json:"nextCursor"`
}

Result represents the response structure for cursor-based pagination

func NewResult

func NewResult[T Item](items []T) Result[T]

NewResult creates a new pagination result T must implement the Item interface for cursor generation

Jump to

Keyboard shortcuts

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