pagetoken

package
v2.0.331 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pagetoken encodes the position of a paged listing as an opaque string and binds it to the request it was issued for.

A token is the base64url encoding of a JSON envelope: a version, a binding and the payload. The binding is a short hash of whatever the caller says the token belongs to (cryptoprov uses the filter and the field mask of a ListKeysRequest), so a token presented with another request is rejected instead of resuming a different listing. Tokens are neither secret nor authenticated: whoever holds one can read and forge it, which only moves that caller's own cursor.

token, err := pagetoken.Encode(binding, cursor{Marker: "m", Offset: 20})
...
var c cursor
err = pagetoken.Decode(binding, token, &c) // errors.Is(err, pagetoken.ErrInvalid)

Index

Constants

View Source
const (

	// MaxTokenSize is the longest token Decode accepts, so a caller-supplied
	// string cannot make it decode an arbitrarily large document.
	MaxTokenSize = 8 << 10
)

Variables

View Source
var ErrInvalid = errors.New("invalid page token")

ErrInvalid is the cause of every Decode failure: a token that is not one, has another version or was issued for another binding.

Functions

func Binding

func Binding(v any) ([]byte, error)

Binding returns the binding of v: a hash of its JSON encoding. v must marshal deterministically, which structs, sorted slices and maps (whose keys encoding/json sorts) do.

func Decode

func Decode(binding []byte, token string, payload any) error

Decode reads the payload of token into payload, which must be a pointer. It fails with a wrapped ErrInvalid when token is malformed, too long, of another version or was issued for another binding.

func Encode

func Encode(binding []byte, payload any) (string, error)

Encode returns the token that carries payload for binding.

Types

This section is empty.

Jump to

Keyboard shortcuts

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