ratelimiter

package
v0.0.0-...-430806f Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2013 License: MIT Imports: 5 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
	Leak_rate  time.Duration // time.Duration for 1 unit of size to leak
	Lastupdate time.Time
	Now        func() time.Time
}

func NewLeakyBucket

func NewLeakyBucket(size uint16, leak_rate 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

type LeakyBucketSer

type LeakyBucketSer struct {
	Size       uint16
	Fill       float64
	Leak_rate  time.Duration // time.Duration for 1 unit of size to leak
	Lastupdate time.Time
}

func (*LeakyBucketSer) DeSerialise

func (b *LeakyBucketSer) DeSerialise() *LeakyBucket

type Memcache

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

func NewMemcache

func NewMemcache(servers string, cacheKeyPrefix string) *Memcache

func (*Memcache) GetBucketFor

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

func (*Memcache) SetBucketFor

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

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
}

Directories

Path Synopsis
Package http rate decorates an gorilla.Mux and prevents too many requests being made
Package http rate decorates an gorilla.Mux and prevents too many requests being made
Package http rate decorates an http.Handler and prevents too many requests being made
Package http rate decorates an http.Handler and prevents too many requests being made

Jump to

Keyboard shortcuts

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