pagination

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConditionNeverMet = errors.New("looped all items and the condition was never met")
)

Functions

func HasNext

func HasNext(page Page) bool

HasNext is a helper function which checks whether there are more pages to fetch

func LoopUntil

func LoopUntil(ctx context.Context, pageable Pageable, untilFunc UntilTrueFunc, opts ...param.Parameter) error

LoopUntil takes a pageable and loops over it until untilFunc returns true or an error.

Types

type CancelFunc

type CancelFunc func()

func AsChan

func AsChan(ctx context.Context, pageable Pageable, opts ...param.Parameter) (chan interface{}, CancelFunc)

AsChan takes a Pageable and returns its Pageable.Content via a channel until there are no more pages or CancelFunc gets called by the consumer.

type Page

type Page interface {
	Num() int
	Size() int
	Total() int
	Options() []param.Parameter
	Content() interface{}
}

type Pageable

type Pageable interface {
	GetPage(ctx context.Context, page, limit int, opts ...param.Parameter) (Page, error)
	NextPage(ctx context.Context, page Page) (Page, error)
}

Pageable should be implemented by evey struct that supports pagination.

type UntilTrueFunc

type UntilTrueFunc func(interface{}) (bool, error)

Jump to

Keyboard shortcuts

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