paginator

package
v0.0.0-...-d7353a2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package paginator contains helpers to convert between AIP-158 page_size/page_token/next_page_token fields and simple offset/limit values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InvalidTokenError

func InvalidTokenError(err error) error

InvalidTokenError annotates the error with InvalidArgument appstatus.

Types

type Paginator

type Paginator struct {
	// The default page size to use if the user does not specify a page size.
	DefaultPageSize int32
	// The max page size to allow the user to request.
	MaxPageSize int32
}

Paginator converts between AIP-158 page_size/page_token/next_page_token fields and a simple offset/limit. Note that offset/limit is susceptible to page tearing during pagination if new items are added to the list during iteration. This paginator makes no attempt to solve this at present, but can be extended to take additional state in the future to address this if necessary.

func (Paginator) Limit

func (p Paginator) Limit(requestedPageSize int32) int32

Limit gets the limit given the page_size field and the configuration stored in the paginator.

func (Paginator) NextPageToken

func (p Paginator) NextPageToken(request proto.Message, offset int64) (string, error)

NextPageToken gets the value to use for the next_page_token field in a response to remember the given offset for the next request. The request message is required to ensure that the user does not change request parameters in the next request (hence making the offset invalid).

func (Paginator) Offset

func (p Paginator) Offset(request proto.Message) (int64, error)

Offset gets the offset given a request message with an AIP-158 page_token field.

Jump to

Keyboard shortcuts

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