Documentation ¶
Index ¶
- Constants
- type GlobalTokenBucket
- func (gtb *GlobalTokenBucket) Close() error
- func (gtb *GlobalTokenBucket) GetBucketCapacity() float64
- func (gtb *GlobalTokenBucket) GetPassThrough() bool
- func (gtb *GlobalTokenBucket) Name() string
- func (gtb *GlobalTokenBucket) Return(ctx context.Context, label string, n float64) (float64, float64)
- func (gtb *GlobalTokenBucket) SetBucketCapacity(bucketCapacity float64)
- func (gtb *GlobalTokenBucket) SetFillAmount(fillAmount float64)
- func (gtb *GlobalTokenBucket) SetPassThrough(passThrough bool)
- func (gtb *GlobalTokenBucket) Take(ctx context.Context, label string, n float64) (bool, time.Duration, float64, float64)
- func (gtb *GlobalTokenBucket) TakeIfAvailable(ctx context.Context, label string, n float64) (bool, time.Duration, float64, float64)
Constants ¶
const (
// TakeNFunction is the name of the function used to take N tokens from the bucket.
TakeNFunction = "TakeN"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GlobalTokenBucket ¶
type GlobalTokenBucket struct {
// contains filtered or unexported fields
}
GlobalTokenBucket implements Limiter.
func NewGlobalTokenBucket ¶
func NewGlobalTokenBucket(dc *distcache.DistCache, name string, interval time.Duration, maxIdleDuration time.Duration, continuousFill bool, ) (*GlobalTokenBucket, error)
NewGlobalTokenBucket creates a new instance of DistCacheRateTracker.
func (*GlobalTokenBucket) Close ¶
func (gtb *GlobalTokenBucket) Close() error
Close cleans up DMap held within the DistCacheRateTracker.
func (*GlobalTokenBucket) GetBucketCapacity ¶
func (gtb *GlobalTokenBucket) GetBucketCapacity() float64
GetBucketCapacity returns the rate limit for the rate limiter.
func (*GlobalTokenBucket) GetPassThrough ¶
func (gtb *GlobalTokenBucket) GetPassThrough() bool
GetPassThrough returns the pass through flag.
func (*GlobalTokenBucket) Name ¶
func (gtb *GlobalTokenBucket) Name() string
Name returns the name of the DistCacheRateTracker.
func (*GlobalTokenBucket) Return ¶
func (gtb *GlobalTokenBucket) Return(ctx context.Context, label string, n float64) (float64, float64)
Return returns n tokens to the bucket.
func (*GlobalTokenBucket) SetBucketCapacity ¶
func (gtb *GlobalTokenBucket) SetBucketCapacity(bucketCapacity float64)
SetBucketCapacity sets the rate limit for the rate limiter.
func (*GlobalTokenBucket) SetFillAmount ¶
func (gtb *GlobalTokenBucket) SetFillAmount(fillAmount float64)
SetFillAmount sets the default fill amount for the rate limiter.
func (*GlobalTokenBucket) SetPassThrough ¶
func (gtb *GlobalTokenBucket) SetPassThrough(passThrough bool)
SetPassThrough sets the pass through flag.
func (*GlobalTokenBucket) Take ¶
func (gtb *GlobalTokenBucket) Take(ctx context.Context, label string, n float64) (bool, time.Duration, float64, float64)
Take increments value in label by n and returns whether n events should be allowed along with the remaining value (limit - new n) after increment and the current count for the label. It also returns the wait time at which the tokens will be available.
func (*GlobalTokenBucket) TakeIfAvailable ¶
func (gtb *GlobalTokenBucket) TakeIfAvailable(ctx context.Context, label string, n float64) (bool, time.Duration, float64, float64)
TakeIfAvailable increments value in label by n and returns whether n events should be allowed along with the remaining value (limit - new n) after increment and the current count for the label. If an error occurred it returns true, 0, 0 and 0 (fail open). It also may return the wait time at which the tokens will be available.