Documentation ¶
Index ¶
- type Count
- type Limit
- func (l *Limit) Enforce(ctx context.Context, ctr *LimitCounter) error
- func (l Limit) EnforceVar(ctx context.Context, s *sync.Map) error
- func (l *Limit) GetCounters(s *sync.Map) *LimitCounter
- func (l *Limit) IsZero() bool
- func (l *Limit) OnExceed(lc *LimitCounter) (e RateError)
- func (l *Limit) String() string
- func (l *Limit) UnmarshalJSON(data []byte) error
- func (l *Limit) UnmarshalText(text []byte) (err error)
- func (l *Limit) UnmarshalYAML(node *yaml.Node) (err error)
- type LimitCounter
- type Limiter
- type Options
- type Rate
- func (d Rate) Clamp(rateMin Rate, rateMax Rate) Rate
- func (d Rate) ClampPeriod(pmin time.Duration, pmax time.Duration) Rate
- func (d Rate) Compare(o Rate) int
- func (d Rate) Faster(o Rate) bool
- func (d Rate) Interval() time.Duration
- func (d Rate) IsPositive() bool
- func (d Rate) IsZero() bool
- func (d Rate) MarshalJSON() ([]byte, error)
- func (d Rate) MarshalText() ([]byte, error)
- func (d Rate) MarshalYAML() (any, error)
- func (d Rate) Rescale(period time.Duration) Rate
- func (d Rate) Slower(o Rate) bool
- func (d Rate) String() string
- func (d *Rate) UnmarshalJSON(data []byte) error
- func (d *Rate) UnmarshalText(text []byte) (err error)
- func (d *Rate) UnmarshalYAML(node *yaml.Node) error
- type RateError
- type Subtick
- type Tick
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limit ¶
type Limit struct {
Options
}
func (*Limit) Enforce ¶
func (l *Limit) Enforce(ctx context.Context, ctr *LimitCounter) error
Enforces a limit given the context and counter.
func (Limit) EnforceVar ¶
Enforces a limit given the context and sync.Map to store counters per client.
func (*Limit) GetCounters ¶
func (l *Limit) GetCounters(s *sync.Map) *LimitCounter
Returns the counter for the given limit, creating it if necessary.
func (*Limit) OnExceed ¶
func (l *Limit) OnExceed(lc *LimitCounter) (e RateError)
Returns the advisory error for exceeding the limit.
func (*Limit) UnmarshalJSON ¶
func (*Limit) UnmarshalText ¶
func (*Limit) UnmarshalYAML ¶
type LimitCounter ¶
type LimitCounter struct {
// contains filtered or unexported fields
}
Limit context is a sliding window counter with backpressure, used to track the rate of events and the current wait queue length.
func (*LimitCounter) Reset ¶
func (c *LimitCounter) Reset()
type Limiter ¶
type Limiter struct { Limit Counter *LimitCounter }
Limiter is a rate limiter with its own local counter.
func LocalLimiter ¶
type Options ¶
type Options struct { ID string `yaml:"id,omitempty"` // Optional identifier. Rate Rate `yaml:"rate"` // The rate to enforce. Burst int32 `yaml:"burst,omitempty"` // The maximum burst size. BlockAfter Rate `yaml:"block_after,omitempty"` // The rate (of excessive requests) after which block duration is advised. BlockFor util.Duration `yaml:"block_for,omitempty"` // The duration to block the client. AdviseClient bool `yaml:"advise,omitempty"` // Whether to advise the client on the block duration. }
Limit defines the options for a rate limiter.
type Rate ¶
func (Rate) IsPositive ¶
func (Rate) MarshalJSON ¶
func (Rate) MarshalText ¶
func (Rate) MarshalYAML ¶
func (*Rate) UnmarshalJSON ¶
func (*Rate) UnmarshalText ¶
func (*Rate) UnmarshalYAML ¶
type RateError ¶
type RateError struct { BlockUntil time.Duration // Advisory block duration to the server. RetryAfter time.Duration // Advisory retry duration to the client. NoHeader bool // Whether to suppress the Retry-After header. }
func (RateError) AdviseClient ¶
Click to show internal directories.
Click to hide internal directories.