Documentation
¶
Index ¶
- Variables
- type Bucket
- func (bucket *Bucket) Count() (int, error)
- func (bucket *Bucket) DynamicFill(rate int, interval chan time.Time) *Watchable
- func (bucket *Bucket) Fill(rate int, interval time.Duration) *Watchable
- func (bucket *Bucket) Put(amount int) error
- func (bucket *Bucket) Take(tokensDesired int) error
- func (bucket *Bucket) TakeAll() (int, error)
- func (bucket *Bucket) Watch(tokens int, duration time.Duration) *Watchable
- type Options
- type Watchable
Constants ¶
This section is empty.
Variables ¶
var ( DefaultMemoryStore = &storage.MemoryStorage{} // Options which use redis as the storage back-end, defaults to the default redis options DefaultRedisStore = &storage.RedisStorage{Client: redis.NewClient(&redis.Options{Addr: ":6379"})} )
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct { // the name of the bucket, may have implications for certain storage providers Name string // contains filtered or unexported fields }
func New ¶
Instantiate the bucket with a given storage object. Test the validity of the storage with storage.Ping().
If a name already exists its storage will be shared with the bucket that created it.
The storage provider might reject a bucket name (and return an error) if the value already assigned to a bucket is unexpected, for example if a name has a string value in redis (which may indicate it is reserved for something else in the database). Redis will also reject sharing a bucket name whose value is 0, this was a personal choice because I found myself incorrectly using bucket names I thought did not exist but actually did (from leftover tests).
func NewWithRedis ¶
Create a bucket with Redis storage
func (*Bucket) DynamicFill ¶
Dynamic fill fills the bucket every time it reads from interval
func (*Bucket) Fill ¶
Start a ticker that will periodically set the token value to a given rate on the defined interval. Returns a Watchable object identical to bucket.Watch, and thus may be canceled and observed.
func (*Bucket) Take ¶
Decrement the token value of a bucket if the number of tokens in the bucket is >= tokensDesired. It will return an error if not enough tokens exist.
type Watchable ¶
type Watchable struct { Success chan error Cancel chan error Failed chan error // The final observable which the user is likely to read from. Though it can only be fired once it is buffered // so that is may be ignored. Finished chan error }
a basic structure from which to cancel or observe an asynchronous action
func NewWatchable ¶
func NewWatchable() *Watchable