goodies: github.com/99designs/goodies/ratelimiter Index | Files

package ratelimiter

import "github.com/99designs/goodies/ratelimiter"

Package ratelimiter implements the Leaky Bucket ratelimiting algorithm with memcached and in-memory backends.

Index

Package Files

leakybucket.go memcache.go memory.go storage.go

Constants

const GC_SIZE int = 100

type LeakyBucket Uses

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 Uses

func NewLeakyBucket(size uint16, leakInterval time.Duration) *LeakyBucket

func (*LeakyBucket) DrainedAt Uses

func (b *LeakyBucket) DrainedAt() time.Time

The time at which this bucket will be completely drained

func (*LeakyBucket) Pour Uses

func (b *LeakyBucket) Pour(amount uint16) bool

func (*LeakyBucket) Serialise Uses

func (b *LeakyBucket) Serialise() *LeakyBucketSer

func (*LeakyBucket) TimeSinceLastUpdate Uses

func (b *LeakyBucket) TimeSinceLastUpdate() time.Duration

func (*LeakyBucket) TimeToDrain Uses

func (b *LeakyBucket) TimeToDrain() time.Duration

The duration until this bucket is completely drained

type LeakyBucketSer Uses

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 Uses

func (b *LeakyBucketSer) DeSerialise() *LeakyBucket

type Memcache Uses

type Memcache struct {
    // contains filtered or unexported fields
}

func NewMemcache Uses

func NewMemcache(servers []string, cacheKeyPrefix string) *Memcache

func (*Memcache) GetBucketFor Uses

func (m *Memcache) GetBucketFor(key string) (*LeakyBucket, error)

func (*Memcache) SetBucketFor Uses

func (m *Memcache) SetBucketFor(key string, bucket LeakyBucket) error

type Memory Uses

type Memory struct {
    // contains filtered or unexported fields
}

func NewMemory Uses

func NewMemory() *Memory

func (*Memory) GarbageCollect Uses

func (m *Memory) GarbageCollect()

func (*Memory) GetBucketFor Uses

func (m *Memory) GetBucketFor(key string) (*LeakyBucket, error)

func (*Memory) SetBucketFor Uses

func (m *Memory) SetBucketFor(key string, bucket LeakyBucket) error

type Storage Uses

type Storage interface {
    GetBucketFor(string) (*LeakyBucket, error)
    SetBucketFor(string, LeakyBucket) error
}

Package ratelimiter imports 6 packages (graph). Updated 2016-08-02. Refresh now. Tools for package owners.