Documentation
¶
Overview ¶
bucket implements a generic, embeddable token bucket algorithm.
Index ¶
Constants ¶
View Source
const ( TPS Rate = 1 KTPS = 1000 * TPS MTPS = 1000 * KTPS GTPS = 1000 * MTPS Unlimited = 0 )
Common rates.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
Represents a token bucket. It is not thread safe.
func New ¶
NewBucket creates a new bucket with the given rate and the maximum bucket size.
If rate is Unlimited, it returns a nil pointer and it is safe to call all Bucket methods on that nil pointer:
b := bucket.NewBucket(Unlimited) b.Has(10) b.Get(10)
func (*Bucket) Get ¶
Get allocates t tockens from the buffer if available, or otherwise returns false.
func (*Bucket) Reset ¶
func (b *Bucket) Reset()
Reset reset the bucket to an empty bucket and starts adding tokens from now.
Click to show internal directories.
Click to hide internal directories.