pagination

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: Apache-2.0 Imports: 2 Imported by: 181

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = fmt.Errorf("pagination token cannot be nil")

Functions

This section is empty.

Types

type Bag

type Bag struct {
	// contains filtered or unexported fields
}

Bag holds pagination states that can be serialized for use as page tokens. It acts as a stack that you can push and pop pagination operations from.

func (*Bag) Current

func (pb *Bag) Current() *PageState

Current returns the current page state for the bag.

func (*Bag) Marshal

func (pb *Bag) Marshal() (string, error)

Marshal returns a string encoding of the state object.

func (*Bag) Next

func (pb *Bag) Next(pageToken string) error

Next pops the current token, and pushes a copy of it with an updated page token.

func (*Bag) NextToken

func (pb *Bag) NextToken(pageToken string) (string, error)

Next pops the current token, and pushes a copy of it with an updated page token.

func (*Bag) PageToken

func (pb *Bag) PageToken() string

PageToken returns the page token for the current state.

func (*Bag) Pop

func (pb *Bag) Pop() *PageState

Pop returns the current page action, and makes the top of the stack the current.

func (*Bag) Push

func (pb *Bag) Push(state PageState)

Push pushes a new page state onto the stack.

func (*Bag) ResourceID

func (pb *Bag) ResourceID() string

ResourceID returns the resource ID for the current state.

func (*Bag) ResourceTypeID

func (pb *Bag) ResourceTypeID() string

ResourceTypeID returns the resource type id for the current state.

func (*Bag) Unmarshal

func (pb *Bag) Unmarshal(input string) error

Unmarshal takes an input string and unmarshals it onto the state object.

type GenBag added in v0.2.64

type GenBag[T any] struct {
	// contains filtered or unexported fields
}

GenBag holds pagination states that can be serialized for use as page tokens. It acts as a stack that you can push and pop pagination operations from. This is a generic version of the Bag struct.

func GenBagFromToken added in v0.2.64

func GenBagFromToken[T any](pToken *Token) (*GenBag[T], error)

func (*GenBag[T]) Current added in v0.2.64

func (pb *GenBag[T]) Current() *T

Current returns the current page state for the bag.

func (*GenBag[T]) Marshal added in v0.2.64

func (pb *GenBag[T]) Marshal() (string, error)

Marshal returns a string encoding of the state object.

func (*GenBag[T]) Pop added in v0.2.64

func (pb *GenBag[T]) Pop() *T

Pop returns the current page action, and makes the top of the stack the current.

func (*GenBag[T]) Push added in v0.2.64

func (pb *GenBag[T]) Push(state T)

Push pushes a new page state onto the stack.

func (*GenBag[T]) Unmarshal added in v0.2.64

func (pb *GenBag[T]) Unmarshal(input string) error

Unmarshal takes an input string and unmarshals it onto the state object.

type PageState

type PageState struct {
	Token          string `json:"token,omitempty"`
	ResourceTypeID string `json:"type,omitempty"`
	ResourceID     string `json:"id,omitempty"`
}

type StreamState added in v0.1.16

type StreamState struct {
	Cursor  string `json:"cursor"`
	HasMore bool   `json:"done"`
}

type StreamToken added in v0.1.16

type StreamToken struct {
	Size   int
	Cursor string
}

type Token

type Token struct {
	Size  int
	Token string
}

Jump to

Keyboard shortcuts

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