pagination

package
v0.0.0-...-41c8d9c Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
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.

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

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

View Source
var FirstPageToken = Token("")

FirstPageToken is used to represent the first page of content.

Functions

This section is empty.

Types

type Key

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

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

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

func NewKey() (k Key, err error)

NewKey generates a new random pagination key.

func (Key) MarshalToken

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

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

func (Key) String

func (k Key) String() string

String implements the fmt.Stringer interface for Key.

func (Key) UnmarshalToken

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

type Token string

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

Jump to

Keyboard shortcuts

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