Documentation ¶
Overview ¶
Package limiter provides a rate limiter
Index ¶
- type CallbackParams
- type Limiter
- func (limiter *Limiter) CancelFunc() context.CancelFunc
- func (limiter *Limiter) Context() context.Context
- func (limiter *Limiter) IsCallbackError() bool
- func (limiter *Limiter) IsCanceled() bool
- func (limiter *Limiter) IsDeadline() bool
- func (limiter *Limiter) IsQueryLimit() bool
- func (limiter *Limiter) IsRateError() bool
- func (limiter *Limiter) LastError() error
- func (limiter *Limiter) NumOfQueries() int
- func (limiter *Limiter) NumOfQueriesByGroupID(id int) int
- func (limiter *Limiter) Run() error
- func (limiter *Limiter) Since() time.Duration
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackParams ¶
type CallbackParams struct { // Limiter is the limiter Limiter *Limiter // GroupID is the id for the concurrency group GroupID int }
CallbackParams represents the callback function parameters
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter represents a limiter
func (*Limiter) CancelFunc ¶
func (limiter *Limiter) CancelFunc() context.CancelFunc
CancelFunc returns the cancel function
func (*Limiter) IsCallbackError ¶
IsCallbackError returns whether the limiter had a rate error
func (*Limiter) IsCanceled ¶
IsCanceled returns whether the limiter is interupted
func (*Limiter) IsDeadline ¶
IsDeadline returns whether the limiter reached deadline
func (*Limiter) IsQueryLimit ¶
IsQueryLimit returns whether the limiter reached query limit
func (*Limiter) IsRateError ¶
IsRateError returns whether the limiter had a rate error
func (*Limiter) NumOfQueries ¶
NumOfQueries returns the number of queries
func (*Limiter) NumOfQueriesByGroupID ¶
NumOfQueriesByGroupID returns the number of queries by the given group id
type Options ¶
type Options struct { // Concurrency level Concurrency uint32 // Limit is the limit for the total number of queries Limit uint32 // QPS is the limit for the number of queries per second QPS uint32 // Duration is the limit for making queries Duration time.Duration // Callback is the function that is invoked on every query Callback func(cbp CallbackParams) error // SignalHandler enables the signal handler SignalHandler bool }
Options represents the options that can be set when creating a new limiter