clair: Index | Files

package pagination

import ""

Package pagination implements a series of utilities for dealing with paginating lists of objects for an API.


Package Files



var ErrInvalidKeyString = errors.New("invalid pagination key string: must be 32-byte URL-safe base64")

ErrInvalidKeyString is returned when the string representing a key is malformed.

var ErrInvalidToken = errors.New("invalid or expired pagination token")

ErrInvalidToken is returned when a token fails to Unmarshal because it was invalid or expired.

var FirstPageToken = Token("")

FirstPageToken is used to represent the first page of content.

type Key Uses

type Key struct {
    // contains filtered or unexported fields

Key represents the key used to cryptographically secure the token being used to keep track of pages.

func KeyFromString Uses

func KeyFromString(keyString string) (k Key, err error)

KeyFromString creates the key for a given string.

Strings must be 32-byte URL-safe base64 representations of the key bytes.

func Must Uses

func Must(k Key, err error) Key

Must is a helper that wraps calls returning a Key and and error and panics if the error is non-nil.

func NewKey Uses

func NewKey() (k Key, err error)

NewKey generates a new random pagination key.

func (Key) MarshalToken Uses

func (k Key) MarshalToken(v interface{}) (Token, error)

MarshalToken encodes an interface into JSON bytes and produces a Token.

func (Key) String Uses

func (k Key) String() string

String implements the fmt.Stringer interface for Key.

func (Key) UnmarshalToken Uses

func (k Key) UnmarshalToken(t Token, v interface{}) error

UnmarshalToken decrypts a Token using provided key and decodes the result into the provided interface.

type Token Uses

type Token string

Token represents an opaque pagination token keeping track of a user's progress iterating through a list of results.

Package pagination imports 5 packages (graph) and is imported by 15 packages. Updated 2018-09-07. Refresh now. Tools for package owners.