pagination

package
v1.2.14-prerelease08 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package pagination is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var ErrIteratorFinished = errors.New("iterator has reached end")

ErrIteratorFinished indicates that Next was called on a finished iterator

Functions

This section is empty.

Types

type Entity

type Entity interface{}

Entity is a generic type which can be operated on by Iterator and Writer

type FetchFn

type FetchFn func(context.Context, PageToken) (Page, error)

FetchFn fetches Page from PageToken. Once a page with nil NextToken is returned no more pages will be fetched.

type Iterator

type Iterator interface {
	Next() (Entity, error)
	HasNext() bool
}

Iterator is used to get entities from a collection of pages. When HasNext returns true it is guaranteed that Next will not return an error. Once iterator returns an error it will never make progress again and will always return that same error. Iterator is not thread safe and does not make defensive in or out copies.

func NewIterator

func NewIterator(
	ctx context.Context,
	startingPageToken PageToken,
	fetchFn FetchFn,
) Iterator

NewIterator constructs a new Iterator

type MockEntity added in v0.15.0

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

MockEntity is a mock of Entity interface.

func NewMockEntity added in v0.15.0

func NewMockEntity(ctrl *gomock.Controller) *MockEntity

NewMockEntity creates a new mock instance.

func (*MockEntity) EXPECT added in v0.15.0

func (m *MockEntity) EXPECT() *MockEntityMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

type MockEntityMockRecorder added in v0.15.0

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

MockEntityMockRecorder is the mock recorder for MockEntity.

type MockIterator added in v0.15.0

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

MockIterator is a mock of Iterator interface.

func NewMockIterator added in v0.15.0

func NewMockIterator(ctrl *gomock.Controller) *MockIterator

NewMockIterator creates a new mock instance.

func (*MockIterator) EXPECT added in v0.15.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockIterator) HasNext added in v0.15.0

func (m *MockIterator) HasNext() bool

HasNext mocks base method.

func (*MockIterator) Next added in v0.15.0

func (m *MockIterator) Next() (Entity, error)

Next mocks base method.

type MockIteratorMockRecorder added in v0.15.0

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

MockIteratorMockRecorder is the mock recorder for MockIterator.

func (*MockIteratorMockRecorder) HasNext added in v0.15.0

func (mr *MockIteratorMockRecorder) HasNext() *gomock.Call

HasNext indicates an expected call of HasNext.

func (*MockIteratorMockRecorder) Next added in v0.15.0

func (mr *MockIteratorMockRecorder) Next() *gomock.Call

Next indicates an expected call of Next.

type MockPageToken added in v0.15.0

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

MockPageToken is a mock of PageToken interface.

func NewMockPageToken added in v0.15.0

func NewMockPageToken(ctrl *gomock.Controller) *MockPageToken

NewMockPageToken creates a new mock instance.

func (*MockPageToken) EXPECT added in v0.15.0

EXPECT returns an object that allows the caller to indicate expected use.

type MockPageTokenMockRecorder added in v0.15.0

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

MockPageTokenMockRecorder is the mock recorder for MockPageToken.

type MockWriter added in v0.15.0

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

MockWriter is a mock of Writer interface.

func NewMockWriter added in v0.15.0

func NewMockWriter(ctrl *gomock.Controller) *MockWriter

NewMockWriter creates a new mock instance.

func (*MockWriter) Add added in v0.15.0

func (m *MockWriter) Add(arg0 Entity) error

Add mocks base method.

func (*MockWriter) EXPECT added in v0.15.0

func (m *MockWriter) EXPECT() *MockWriterMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockWriter) FirstFlushedPage added in v0.15.0

func (m *MockWriter) FirstFlushedPage() PageToken

FirstFlushedPage mocks base method.

func (*MockWriter) Flush added in v0.15.0

func (m *MockWriter) Flush() error

Flush mocks base method.

func (*MockWriter) FlushIfNotEmpty added in v0.15.0

func (m *MockWriter) FlushIfNotEmpty() error

FlushIfNotEmpty mocks base method.

func (*MockWriter) FlushedPages added in v0.15.0

func (m *MockWriter) FlushedPages() []PageToken

FlushedPages mocks base method.

func (*MockWriter) LastFlushedPage added in v0.15.0

func (m *MockWriter) LastFlushedPage() PageToken

LastFlushedPage mocks base method.

type MockWriterMockRecorder added in v0.15.0

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

MockWriterMockRecorder is the mock recorder for MockWriter.

func (*MockWriterMockRecorder) Add added in v0.15.0

func (mr *MockWriterMockRecorder) Add(arg0 interface{}) *gomock.Call

Add indicates an expected call of Add.

func (*MockWriterMockRecorder) FirstFlushedPage added in v0.15.0

func (mr *MockWriterMockRecorder) FirstFlushedPage() *gomock.Call

FirstFlushedPage indicates an expected call of FirstFlushedPage.

func (*MockWriterMockRecorder) Flush added in v0.15.0

func (mr *MockWriterMockRecorder) Flush() *gomock.Call

Flush indicates an expected call of Flush.

func (*MockWriterMockRecorder) FlushIfNotEmpty added in v0.15.0

func (mr *MockWriterMockRecorder) FlushIfNotEmpty() *gomock.Call

FlushIfNotEmpty indicates an expected call of FlushIfNotEmpty.

func (*MockWriterMockRecorder) FlushedPages added in v0.15.0

func (mr *MockWriterMockRecorder) FlushedPages() *gomock.Call

FlushedPages indicates an expected call of FlushedPages.

func (*MockWriterMockRecorder) LastFlushedPage added in v0.15.0

func (mr *MockWriterMockRecorder) LastFlushedPage() *gomock.Call

LastFlushedPage indicates an expected call of LastFlushedPage.

type Page

type Page struct {
	NextToken    PageToken
	CurrentToken PageToken
	Entities     []Entity
}

Page contains a PageToken which identifies the current page, a PageToken which identifies the next page and a list of Entity.

type PageToken

type PageToken interface{}

PageToken identifies a page

type ShouldFlushFn

type ShouldFlushFn func(Page) bool

ShouldFlushFn returns true if given page should be flushed false otherwise.

type WriteFn

type WriteFn func(Page) (PageToken, error)

WriteFn writes given Page to underlying sink. The Pages's NextToken will always be nil, its the responsibility of WriteFn to construct and return the next PageToken, or return an error on failure.

type Writer

type Writer interface {
	Add(Entity) error
	Flush() error
	FlushIfNotEmpty() error
	FlushedPages() []PageToken
	FirstFlushedPage() PageToken
	LastFlushedPage() PageToken
}

Writer is used to buffer and write entities to underlying store.

func NewWriter

func NewWriter(
	writeFn WriteFn,
	shouldFlushFn ShouldFlushFn,
	startingPage PageToken,
) Writer

NewWriter constructs a new Writer

Jump to

Keyboard shortcuts

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