paginator

package
v1.3.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MPL-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateIndexGetter

type CreateIndexGetter interface {
	GetCreateIndex() uint64
}

CreateIndexGetter is the interface that must be implemented by structs that need to have their CreateIndex as part of the pagination token.

type Filter

type Filter interface {
	// Evaluate returns true if the element should be added to the page.
	Evaluate(interface{}) (bool, error)
}

Filter is the interface that must be implemented to skip values when using the Paginator.

type GenericFilter

type GenericFilter struct {
	Allow func(interface{}) (bool, error)
}

GenericFilter wraps a function that can be used to provide simple or in scope filtering.

func (GenericFilter) Evaluate

func (f GenericFilter) Evaluate(raw interface{}) (bool, error)

type IDGetter

type IDGetter interface {
	GetID() string
}

IDGetter is the interface that must be implemented by structs that need to have their ID as part of the pagination token.

type Iterator

type Iterator interface {
	// Next returns the next element to be considered for pagination.
	// The page will end if nil is returned.
	Next() interface{}
}

Iterator is the interface that must be implemented to supply data to the Paginator.

type NamespaceFilter

type NamespaceFilter struct {
	AllowableNamespaces map[string]bool
}

NamespaceFilter skips elements with a namespace value that is not in the allowable set.

func (NamespaceFilter) Evaluate

func (f NamespaceFilter) Evaluate(raw interface{}) (bool, error)

type NamespaceGetter

type NamespaceGetter interface {
	GetNamespace() string
}

NamespaceGetter is the interface that must be implemented by structs that need to have their Namespace as part of the pagination token.

type Paginator

type Paginator struct {
	// contains filtered or unexported fields
}

Paginator wraps an iterator and returns only the expected number of pages.

func NewPaginator

func NewPaginator(iter Iterator, tokenizer Tokenizer, filters []Filter,
	opts structs.QueryOptions, appendFunc func(interface{}) error) (*Paginator, error)

NewPaginator returns a new Paginator.

func (*Paginator) Page

func (p *Paginator) Page() (string, error)

Page populates a page by running the append function over all results. Returns the next token.

type StructsTokenizer

type StructsTokenizer struct {
	// contains filtered or unexported fields
}

StructsTokenizer is an pagination token generator that can create different formats of pagination tokens based on common fields found in the structs package.

func NewStructsTokenizer

func NewStructsTokenizer(it Iterator, opts StructsTokenizerOptions) StructsTokenizer

NewStructsTokenizer returns a new StructsTokenizer.

func (StructsTokenizer) GetToken

func (it StructsTokenizer) GetToken(raw interface{}) string

type StructsTokenizerOptions

type StructsTokenizerOptions struct {
	WithCreateIndex bool
	WithNamespace   bool
	WithID          bool
}

StructsTokenizerOptions is the configuration provided to a StructsTokenizer.

type Tokenizer

type Tokenizer interface {
	// GetToken returns the pagination token for the given element.
	GetToken(interface{}) string
}

Tokenizer is the interface that must be implemented to provide pagination tokens to the Paginator.

Jump to

Keyboard shortcuts

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