Documentation
¶
Overview ¶
Package pagination provides a ways to iterate over collections. For that purposes, it defines iterators and paginators, which act as an abstraction over the process of iterating over an entire result set of a truncated API operation returning pages.
Index ¶
- type AbstractPaginator
- func (a *AbstractPaginator) Close() error
- func (a *AbstractPaginator) GetContext() context.Context
- func (a *AbstractPaginator) GetCurrentPage() (page IPage, err error)
- func (a *AbstractPaginator) GetNext() (item *interface{}, err error)
- func (a *AbstractPaginator) HasNext() bool
- func (a *AbstractPaginator) SetCurrentPage(page IPage) (err error)
- func (a *AbstractPaginator) Stop() context.CancelFunc
- type IIterator
- type IPage
- type IPaginator
- type IStream
- type IStreamPaginator
- type MockItem
- type MockPage
- func (m *MockPage) AppendItem(i *MockItem) error
- func (m *MockPage) GetFuture(ctx context.Context) (future IPage, err error)
- func (m *MockPage) GetItemCount() (int64, error)
- func (m *MockPage) GetItemIterator() (iterator IIterator, err error)
- func (m *MockPage) GetNext(ctx context.Context) (page IPage, err error)
- func (m *MockPage) HasFuture() bool
- func (m *MockPage) HasNext() bool
- func (m *MockPage) SetFuture(future IStream) error
- func (m *MockPage) SetIndexes(firstIndex int)
- func (m *MockPage) SetNext(next IStream) error
- type MockPageIterator
- type StreamPaginator
- func (s *StreamPaginator) Close() error
- func (s *StreamPaginator) DryUp() error
- func (s *StreamPaginator) GetCurrentPage() (IPage, error)
- func (s *StreamPaginator) GetNext() (*interface{}, error)
- func (s *StreamPaginator) HasNext() bool
- func (s *StreamPaginator) IsRunningDry() bool
- func (s *StreamPaginator) Stop() context.CancelFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AbstractPaginator ¶
type AbstractPaginator struct {
// contains filtered or unexported fields
}
func (*AbstractPaginator) Close ¶
func (a *AbstractPaginator) Close() error
func (*AbstractPaginator) GetContext ¶
func (a *AbstractPaginator) GetContext() context.Context
func (*AbstractPaginator) GetCurrentPage ¶
func (a *AbstractPaginator) GetCurrentPage() (page IPage, err error)
func (*AbstractPaginator) GetNext ¶
func (a *AbstractPaginator) GetNext() (item *interface{}, err error)
func (*AbstractPaginator) HasNext ¶
func (a *AbstractPaginator) HasNext() bool
func (*AbstractPaginator) SetCurrentPage ¶
func (a *AbstractPaginator) SetCurrentPage(page IPage) (err error)
func (*AbstractPaginator) Stop ¶
func (a *AbstractPaginator) Stop() context.CancelFunc
type IIterator ¶
type IIterator interface {
// HasNext returns whether there are more items available or not.
HasNext() bool
// GetNext returns the next item.
GetNext() (*interface{}, error)
}
IIterator defines an iterator over a collection of items.
func NewMockPageIterator ¶
type IPage ¶
type IPage interface {
// HasNext states whether more pages are accessible.
HasNext() bool
// GetNext returns the next page.
GetNext(ctx context.Context) (IPage, error)
// GetItemIterator returns an iterator over the page's items.
GetItemIterator() (IIterator, error)
// GetItemCount returns the number of items in this page
GetItemCount() (int64, error)
}
IPage defines a generic page for a collection.
type IPaginator ¶
type IPaginator interface {
io.Closer
IIterator
// Stop returns a stop function which stops the iteration.
Stop() context.CancelFunc
// GetCurrentPage returns the current page.
GetCurrentPage() (IPage, error)
}
IPaginator is an iterator over multiple pages
func NewAbstractPaginator ¶
func NewAbstractPaginator(ctx context.Context, firstPage IPage) IPaginator
func NewCollectionPaginator ¶
func NewCollectionPaginator(ctx context.Context, fetchFirstPage func(context.Context) (IPage, error)) (paginator IPaginator, err error)
NewCollectionPaginator creates a paginator over a collection.
type IStream ¶
type IStream interface {
IPage
// HasFuture states whether there may be future items.
HasFuture() bool
// GetFuture returns the future page.
GetFuture(ctx context.Context) (IPage, error)
}
IStream defines a page for a collection which does not have any known ending.
func GenerateEmptyPage ¶
func GenerateEmptyPage() IStream
func GenerateMockCollection ¶
func GenerateMockPage ¶
func GenerateMockStream ¶
type IStreamPaginator ¶
type IStreamPaginator interface {
IPaginator
// DryUp indicates to the stream that it will soon run out.
DryUp() error
// IsRunningDry indicates whether the stream is about to run out.
IsRunningDry() bool
}
IStreamPaginator is an iterator over a stream. A stream is a collection without any know ending.
func NewStreamPaginator ¶
func NewStreamPaginator(ctx context.Context, runOutTimeOut, backoff time.Duration, fetchFirstPage func(context.Context) (IStream, error)) (paginator IStreamPaginator, err error)
NewStreamPaginator creates a paginator over a stream. runOutTimeOut corresponds to the grace period between the stream being marked as running dry and the iteration actually ending backoff corresponds to the backoff time between page iteration.
type MockItem ¶
func GenerateMockItem ¶
func GenerateMockItem() *MockItem
type MockPage ¶
type MockPage struct {
// contains filtered or unexported fields
}
func (*MockPage) AppendItem ¶
func (*MockPage) GetItemCount ¶
func (*MockPage) GetItemIterator ¶
func (*MockPage) SetIndexes ¶
type MockPageIterator ¶
type MockPageIterator struct {
// contains filtered or unexported fields
}
func (*MockPageIterator) GetNext ¶
func (m *MockPageIterator) GetNext() (item *interface{}, err error)
func (*MockPageIterator) HasNext ¶
func (m *MockPageIterator) HasNext() bool
type StreamPaginator ¶
type StreamPaginator struct {
AbstractPaginator
// contains filtered or unexported fields
}
func (*StreamPaginator) Close ¶
func (s *StreamPaginator) Close() error
func (*StreamPaginator) DryUp ¶
func (s *StreamPaginator) DryUp() error
func (*StreamPaginator) GetCurrentPage ¶
func (s *StreamPaginator) GetCurrentPage() (IPage, error)
func (*StreamPaginator) GetNext ¶
func (s *StreamPaginator) GetNext() (*interface{}, error)
func (*StreamPaginator) HasNext ¶
func (s *StreamPaginator) HasNext() bool
func (*StreamPaginator) IsRunningDry ¶
func (s *StreamPaginator) IsRunningDry() bool
func (*StreamPaginator) Stop ¶
func (s *StreamPaginator) Stop() context.CancelFunc