Help us shape the future of Go! Take the 2026 Go Developer Survey

pagination

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 162

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func NewRestartActionError added in v0.42.6

func NewRestartActionError(restartPageToken, reason string) error

NewRestartActionError builds the error a connector returns when the provider rejected the request's page token. An empty restartPageToken restarts the action from its first page.

func RestartActionFromError added in v0.42.6

func RestartActionFromError(err error) (*v2.RestartAction, bool)

RestartActionFromError returns the detail when the first status in err's chain carries an RestartAction, which is what a gRPC server serializes from the same error. It does not check the status code; the caller decides which codes honor the detail.

func SurfaceRestartAction added in v0.42.7

func SurfaceRestartAction(err error) error

SurfaceRestartAction returns err unchanged unless it wraps a RestartActionError that RestartActionFromError does not see because another status error comes first in the chain. Then it returns an error whose status is FailedPrecondition with the RestartAction detail and err's full message, wrapping err. Call it where a connector's error becomes a gRPC status; connectorbuilder's list handlers do.

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 RestartActionError added in v0.42.6

type RestartActionError struct {
	RestartPageToken string
	Reason           string
}

RestartActionError is returned by a paginated list method when the request's page token can no longer be used. The syncer restarts the action at RestartPageToken; see v2.RestartAction.

The restart is honored only when the error comes straight from the action's own list call (ListResourceTypes, or ListResources, ListEntitlements, ListGrants, ListStaticEntitlements for a resource type) with code FailedPrecondition or Aborted. Returned from any other call (GetResource, a spawned cursor), or under another code, it fails the sync with ErrRestartRejected. A legacy sqlite c1z passes it through unchanged.

A connector built with connectorbuilder may return it bare, wrapped with %w, or behind another status error (uhttp.WrapErrors, errors.Join with a status error): the builder's list handlers call SurfaceRestartAction, so the restart wins over the outer code. A hand-rolled gRPC server must call SurfaceRestartAction itself or return the error bare, because gRPC serializes the first status in the chain and drops the rest.

func (*RestartActionError) Error added in v0.42.6

func (e *RestartActionError) Error() string

func (*RestartActionError) GRPCStatus added in v0.42.6

func (e *RestartActionError) GRPCStatus() *status.Status

GRPCStatus carries the detail across the connector gRPC boundary, which flattens handler errors to a status.

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