pagination

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Paginator

func Paginator[T any](ctx context.Context, listFunc ListFunc[T], processFunc ProcessFunc[T], rateLimitFunc RateLimitFunc, Opts *PaginatorOpts) ([]T, error)

Types

type ListFunc

type ListFunc[T any] interface {
	List(ctx context.Context, opt *github.ListOptions) ([]T, *github.Response, error)
}

ListFunc is an interface that returns a list of items for the given type for example it could be:

type listFunc struct {
	client *github.Client
}

func (l *listFunc) List(ctx context.Context, opt *github.ListOptions) ([]*github.Repository, *github.Response, error) {
	t, r, err := l.client.Apps.ListRepos(ctx, opt)
	return t.Repositories, r, err
}

type PaginatorOpts

type PaginatorOpts struct {
	*github.ListOptions
}

type ProcessFunc

type ProcessFunc[T any] interface {
	Process(ctx context.Context, item T) error
}

ProcessFunc is a function that processes an item for the given type this is optional as the user may not want to process the items so they can input a skip function that does nothing example:

type processFunc struct {
	client *github.Client
}

func (p *processFunc) Process(ctx context.Context, item *github.Repository) error {
	fmt.Println(item.GetName())
	return nil
}

type RateLimitFunc

type RateLimitFunc interface {
	RateLimit(ctx context.Context, resp *github.Response) (bool, error)
}

RateLimitFunc is a function that handles rate limiting it returns a bool to indicate if the pagination should continue and an error if the users wishes to return more information/errors example:

type rateLimitFunc struct {
}

func (r *rateLimitFunc) RateLimit(ctx context.Context, resp *github.Response) (bool, error) {
	return true, nil
}

Jump to

Keyboard shortcuts

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