githubpagination

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(base http.RoundTripper, opts ...Option) *http.Client

func WithOverrideConfig

func WithOverrideConfig(ctx context.Context, opts ...Option) context.Context

WithOverrideConfig adds config overrides to the context. The overrides are applied on top of the existing config. Allows for request-specific overrides.

Types

type Async

type Async[DataType any] struct {
	OnNext OnNextResponse[DataType]
	// contains filtered or unexported fields
}

func NewAsync

func NewAsync[DataType any](onNext OnNextResponseSlice[DataType]) *Async[DataType]

NewAsync creates a new Async instance for non-search results. Note: you can use this with search results, but the incomplete_results and total_count fields will not be available.

func NewAsyncSearch

func NewAsyncSearch[DataType any](onNext OnNextResponse[DataType]) *Async[DataType]

NewAsyncSearch creates a new Async instance for search results. It is designed to be used with search results, so that the incomplete_results and total_count fields are available.

func (*Async[DataType]) HandleError

func (a *Async[DataType]) HandleError(resp *http.Response, err error)

func (*Async[DataType]) HandleFinish

func (a *Async[DataType]) HandleFinish(resp *http.Response, pageCount int)

func (*Async[DataType]) HandlePage

func (a *Async[DataType]) HandlePage(data *searchresult.Typed[DataType], resp *http.Response) error

func (*Async[DataType]) Paginate

func (a *Async[DataType]) Paginate(requestFn any, args ...any) error

Paginate paginates through the results of a request function.

type Config

type Config struct {
	Disabled       bool
	DefaultPerPage int
	MaxNumOfPages  int
	Driver         PaginationDriver
}

func (*Config) ApplyOptions

func (c *Config) ApplyOptions(opts ...Option)

ApplyOptions applies the options to the config.

func (*Config) GetContextedConfig

func (c *Config) GetContextedConfig(ctx context.Context) *Config

GetContextedConfig returns the config overrides from the context, if any.

func (*Config) GetDriver

func (c *Config) GetDriver() PaginationDriver

func (*Config) GetRequestConfig

func (c *Config) GetRequestConfig(request *http.Request) *Config

GetRequestConfig returns the config overrides from the request context, if any.

func (*Config) IsPaginationOverflow

func (c *Config) IsPaginationOverflow(pageCount int) bool

func (*Config) UpdateRequest

func (c *Config) UpdateRequest(request *http.Request) *http.Request

type ConfigOverridesKey

type ConfigOverridesKey struct{}

type GitHubPagination

type GitHubPagination struct {
	Base http.RoundTripper
	// contains filtered or unexported fields
}

func New

func New(base http.RoundTripper, opts ...Option) *GitHubPagination

func (*GitHubPagination) RoundTrip

func (g *GitHubPagination) RoundTrip(request *http.Request) (*http.Response, error)

type OnNextResponse

type OnNextResponse[DataType any] func(*http.Response, *searchresult.Typed[DataType]) error

type OnNextResponseSlice

type OnNextResponseSlice[DataType any] func(*http.Response, []*DataType) error

type Option

type Option func(*Config)

func GetConfigOverrides

func GetConfigOverrides(ctx context.Context) []Option

GetConfigOverrides returns the config overrides from the context, if any.

func WithDriver

func WithDriver(driver drivers.Driver) Option

WithDriver sets the driver for paginated requests. Available drivers out-of-the-box: - sync (default): handle pagination synchronously. - raw_async: handle pagination asynchronously using raw HTTP requests/responses. - async: handle pagination asynchronously with github orientation.

func WithMaxNumOfPages

func WithMaxNumOfPages(maxNumOfPages int) Option

WithMaxNumOfPages sets the maximum number of pages for paginated requests. This enables the client to limit the number of pages to be fetched.

func WithPaginationDisabled

func WithPaginationDisabled() Option

WithPaginationDisabled disables the pagination for paginated requests. This may be used to override a previous WithPaginationEnabled option, e.g., on a per-request basis.

func WithPaginationEnabled

func WithPaginationEnabled() Option

WithPaginationEnabled enables the pagination for paginated requests. This is the default behavior. This may be used to override a previous WithPaginationDisabled option, e.g., on a per-request basis.

func WithPerPage

func WithPerPage(perPage int) Option

WithPerPage sets the default per-page value for paginated requests.

type PaginationDriver

type PaginationDriver = drivers.Driver

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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