...

Package pagination

import "go.einride.tech/aip/pagination"
Overview
Index

Overview ▾

Package pagination provides primitives for implementing AIP pagination.

See: https://google.aip.dev/158 (Pagination).

func DecodePageTokenStruct

func DecodePageTokenStruct(s string, v interface{}) error

DecodePageTokenStruct decodes an encoded page token into an arbitrary struct.

func EncodePageTokenStruct

func EncodePageTokenStruct(v interface{}) string

EncodePageTokenStruct encodes an arbitrary struct as a page token.

type PageToken

PageToken is a page token that uses an offset to delineate which page to fetch.

type PageToken struct {
    // Offset of the page.
    Offset int64
    // RequestChecksum is the checksum of the request that generated the page token.
    RequestChecksum uint32
}

func ParsePageToken

func ParsePageToken(request Request) (_ PageToken, err error)

ParsePageToken parses an offset-based page token from the provided Request.

If the request does not have a page token, a page token with offset 0 will be returned.

func (PageToken) Next

func (p PageToken) Next(request Request) PageToken

Next returns the next page token for the provided Request.

func (PageToken) String

func (p PageToken) String() string

String returns a string representation of the page token.

type Request

Request is an interface for paginated request messages.

See: https://google.aip.dev/158 (Pagination).

type Request interface {
    proto.Message
    // GetPageToken returns the page token of the request.
    GetPageToken() string
    // GetPageSize returns the page size of the request.
    GetPageSize() int32
}