Documentation
¶
Index ¶
- func PerDay(maxAttempts int) contractshttp.Limit
- func PerDays(decayDays, maxAttempts int) contractshttp.Limit
- func PerHour(maxAttempts int) contractshttp.Limit
- func PerHours(decayHours, maxAttempts int) contractshttp.Limit
- func PerMinute(maxAttempts int) contractshttp.Limit
- func PerMinutes(decayMinutes, maxAttempts int) contractshttp.Limit
- type Bucket
- type Limit
- type Store
- func (r *Store) Burst(ctx context.Context, key string, tokens uint64) error
- func (r *Store) Get(ctx context.Context, key string) (tokens uint64, remaining uint64, err error)
- func (r *Store) Set(ctx context.Context, key string, tokens uint64, interval time.Duration) error
- func (r *Store) Take(ctx context.Context, key string) (tokens uint64, remaining uint64, reset uint64, ok bool, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PerDay ¶
func PerDay(maxAttempts int) contractshttp.Limit
func PerDays ¶
func PerDays(decayDays, maxAttempts int) contractshttp.Limit
func PerHour ¶
func PerHour(maxAttempts int) contractshttp.Limit
func PerHours ¶
func PerHours(decayHours, maxAttempts int) contractshttp.Limit
func PerMinute ¶
func PerMinute(maxAttempts int) contractshttp.Limit
func PerMinutes ¶
func PerMinutes(decayMinutes, maxAttempts int) contractshttp.Limit
Types ¶
type Bucket ¶ added in v1.15.0
type Bucket struct {
// AvailableTokens is the current point-in-time number of tokens remaining.
AvailableTokens uint64
// Interval is the time at which ticking should occur.
Interval time.Duration
// LastTick is the last clock tick, used to re-calculate the number of tokens on the Bucket.
LastTick uint64
// MaxTokens is the maximum number of tokens permitted on the Bucket at any time.
// The number of available tokens will never exceed this value.
MaxTokens uint64
// StartTime is the number of nanoseconds from unix epoch when this Bucket was initially created.
StartTime uint64
}
Bucket is an internal wrapper around a taker.
type Limit ¶
type Limit struct {
// The store instance.
Store contractshttp.Store
// The response generator callback.
ResponseCallback func(ctx contractshttp.Context)
// The rate limit signature key.
Key string
}
func (*Limit) Response ¶
func (r *Limit) Response(callable func(ctx contractshttp.Context)) contractshttp.Limit
type Store ¶ added in v1.15.0
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Burst ¶ added in v1.15.0
Burst adds the provided value to the Bucket's currently available tokens.
func (*Store) Take ¶ added in v1.15.0
func (r *Store) Take(ctx context.Context, key string) (tokens uint64, remaining uint64, reset uint64, ok bool, err error)
Take attempts to remove a token from the named key. If the take is successful, it returns true, otherwise false. It also returns the configured limit, remaining tokens, and reset time.
Click to show internal directories.
Click to hide internal directories.