package ratelimiter
import "github.com/hpcloud/tail/ratelimiter"
Package ratelimiter implements the Leaky Bucket ratelimiting algorithm with memcached and in-memory backends.
Index ¶
- Constants
- type LeakyBucket
- func NewLeakyBucket(size uint16, leakInterval time.Duration) *LeakyBucket
- func (b *LeakyBucket) DrainedAt() time.Time
- func (b *LeakyBucket) Pour(amount uint16) bool
- func (b *LeakyBucket) Serialise() *LeakyBucketSer
- func (b *LeakyBucket) TimeSinceLastUpdate() time.Duration
- func (b *LeakyBucket) TimeToDrain() time.Duration
- type LeakyBucketSer
- type Memory
- func NewMemory() *Memory
- func (m *Memory) GarbageCollect()
- func (m *Memory) GetBucketFor(key string) (*LeakyBucket, error)
- func (m *Memory) SetBucketFor(key string, bucket LeakyBucket) error
- type Storage
Constants ¶
const GC_SIZE int = 100
Types ¶
type LeakyBucket ¶
type LeakyBucket struct { Size uint16 Fill float64 LeakInterval time.Duration // time.Duration for 1 unit of size to leak Lastupdate time.Time Now func() time.Time }
func NewLeakyBucket ¶
func NewLeakyBucket(size uint16, leakInterval time.Duration) *LeakyBucket
func (*LeakyBucket) DrainedAt ¶
func (b *LeakyBucket) DrainedAt() time.Time
The time at which this bucket will be completely drained
func (*LeakyBucket) Pour ¶
func (b *LeakyBucket) Pour(amount uint16) bool
func (*LeakyBucket) Serialise ¶
func (b *LeakyBucket) Serialise() *LeakyBucketSer
func (*LeakyBucket) TimeSinceLastUpdate ¶
func (b *LeakyBucket) TimeSinceLastUpdate() time.Duration
func (*LeakyBucket) TimeToDrain ¶
func (b *LeakyBucket) TimeToDrain() time.Duration
The duration until this bucket is completely drained
type LeakyBucketSer ¶
type LeakyBucketSer struct { Size uint16 Fill float64 LeakInterval time.Duration // time.Duration for 1 unit of size to leak Lastupdate time.Time }
func (*LeakyBucketSer) DeSerialise ¶
func (b *LeakyBucketSer) DeSerialise() *LeakyBucket
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func NewMemory ¶
func NewMemory() *Memory
func (*Memory) GarbageCollect ¶
func (m *Memory) GarbageCollect()
func (*Memory) GetBucketFor ¶
func (m *Memory) GetBucketFor(key string) (*LeakyBucket, error)
func (*Memory) SetBucketFor ¶
func (m *Memory) SetBucketFor(key string, bucket LeakyBucket) error
type Storage ¶
type Storage interface { GetBucketFor(string) (*LeakyBucket, error) SetBucketFor(string, LeakyBucket) error }
Source Files ¶
leakybucket.go memory.go storage.go
- Version
- v1.0.0 (latest)
- Published
- Apr 28, 2016
- Platform
- darwin/amd64
- Imports
- 2 packages
- Last checked
- 3 weeks ago –
Tools for package owners.