Documentation ¶
Index ¶
- Constants
- type Clock
- type Config
- type Interceptor
- func (i *Interceptor) BelongTo() (componentTypes []string)
- func (i *Interceptor) Category() api.Category
- func (i *Interceptor) Config() interface{}
- func (i *Interceptor) IgnoreRetry() bool
- func (i *Interceptor) Init(context api.Context) error
- func (i *Interceptor) Intercept(invoker source.Invoker, invocation source.Invocation) api.Result
- func (i *Interceptor) Order() int
- func (i *Interceptor) Start() error
- func (i *Interceptor) Stop()
- func (i *Interceptor) String() string
- func (i *Interceptor) Type() api.Type
- type Limiter
- type Option
Constants ¶
const Type = "rateLimit"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
Clock is the minimum necessary interface to instantiate a rate limiter with a clock or mock clock, compatible with clocks created using github.com/andres-erbsen/clock.
type Config ¶
type Config struct { interceptor.ExtensionConfig `yaml:",inline"` Qps int `yaml:"qps,omitempty" default:"2048" validate:"gte=0"` }
type Interceptor ¶
type Interceptor struct {
// contains filtered or unexported fields
}
func (*Interceptor) BelongTo ¶
func (i *Interceptor) BelongTo() (componentTypes []string)
func (*Interceptor) Category ¶
func (i *Interceptor) Category() api.Category
func (*Interceptor) Config ¶
func (i *Interceptor) Config() interface{}
func (*Interceptor) IgnoreRetry ¶
func (i *Interceptor) IgnoreRetry() bool
func (*Interceptor) Intercept ¶
func (i *Interceptor) Intercept(invoker source.Invoker, invocation source.Invocation) api.Result
func (*Interceptor) Order ¶
func (i *Interceptor) Order() int
func (*Interceptor) Start ¶
func (i *Interceptor) Start() error
func (*Interceptor) Stop ¶
func (i *Interceptor) Stop()
func (*Interceptor) String ¶
func (i *Interceptor) String() string
func (*Interceptor) Type ¶
func (i *Interceptor) Type() api.Type
type Limiter ¶
Limiter is used to rate-limit some process, possibly across goroutines. The process is expected to call Take() before every iteration, which may block to throttle the goroutine.
func NewUnlimited ¶
func NewUnlimited() Limiter
NewUnlimited returns a RateLimiter that is not limited.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a Limiter.
var WithoutSlack Option = slackOption(0)
WithoutSlack is an Option for ratelimit.New that initializes the limiter without any initial tolerance for bursts of traffic.
func Per ¶
Per allows configuring limits for different time windows.
The default window is one second, so New(100) produces a one hundred per second (100 Hz) rate limiter.
New(2, Per(60*time.Second)) creates a 2 per minute rate limiter.
func WithClock ¶
WithClock returns an option for ratelimit.New that provides an alternate Clock implementation, typically a mock Clock for testing.
func WithoutLock ¶
func WithoutLock() Option