ratelimiter

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2015 License: MIT, MIT, MIT Imports: 2 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const GC_SIZE int = 100

Variables

This section is empty.

Functions

This section is empty.

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL