Documentation ¶
Index ¶
Constants ¶
View Source
const ( GET = iota POST DELETE )
Variables ¶
View Source
var ( ErrKeyEmpty = errors.New("Key cannot be empty") ErrCountZero = errors.New("Count should be greater than zero") ErrLimitZero = errors.New("Limit should be greater than zero") ErrCountLimit = errors.New("Limit should be greater than count") ErrZeroDuration = errors.New("Duration cannot be zero") )
View Source
var (
ErrLimitReached = errors.New("Limit reached")
)
View Source
var (
ErrNotFound = errors.New("Not found")
)
Functions ¶
func NewMemcacheClient ¶
Types ¶
type DummyStorage ¶
type DummyStorage struct {
// contains filtered or unexported fields
}
func NewDummyStorage ¶
func NewDummyStorage() *DummyStorage
func (*DummyStorage) Delete ¶
func (d *DummyStorage) Delete(key string) error
func (*DummyStorage) Get ¶
func (d *DummyStorage) Get(key string) (*TokenBucket, error)
func (*DummyStorage) Set ¶
func (d *DummyStorage) Set(key string, bucket *TokenBucket, _ time.Duration) error
type HttpServer ¶
type HttpServer struct {
// contains filtered or unexported fields
}
func NewHttpServer ¶
func NewHttpServer(limiter Limiter, logger *log.Logger) *HttpServer
func (*HttpServer) ServeHTTP ¶
func (s *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
type MemcacheStorage ¶
type MemcacheStorage struct {
// contains filtered or unexported fields
}
func NewMemcacheStorage ¶
func NewMemcacheStorage(client *memcache.Client, prefix string) *MemcacheStorage
func (*MemcacheStorage) Delete ¶
func (ms *MemcacheStorage) Delete(key string) error
func (*MemcacheStorage) Get ¶
func (ms *MemcacheStorage) Get(key string) (*TokenBucket, error)
func (*MemcacheStorage) Set ¶
func (ms *MemcacheStorage) Set(key string, bucket *TokenBucket, duration time.Duration) error
type RedisStorage ¶
type RedisStorage struct {
// contains filtered or unexported fields
}
func NewRedisStorage ¶
func NewRedisStorage(pool *redis.Pool, prefix string) *RedisStorage
func (*RedisStorage) Delete ¶
func (rs *RedisStorage) Delete(key string) error
func (*RedisStorage) Get ¶
func (rs *RedisStorage) Get(key string) (*TokenBucket, error)
func (*RedisStorage) Set ¶
func (rs *RedisStorage) Set(key string, bucket *TokenBucket, duration time.Duration) error
type SingleThreadLimiter ¶
type SingleThreadLimiter struct {
// contains filtered or unexported fields
}
func NewSingleThreadLimiter ¶
func NewSingleThreadLimiter(storage Storage) *SingleThreadLimiter
func (*SingleThreadLimiter) Delete ¶
func (l *SingleThreadLimiter) Delete(key string) error
func (*SingleThreadLimiter) Start ¶
func (l *SingleThreadLimiter) Start()
func (*SingleThreadLimiter) Stop ¶
func (l *SingleThreadLimiter) Stop()
type Storage ¶
type Storage interface { Get(key string) (*TokenBucket, error) Set(key string, bucket *TokenBucket, expire time.Duration) error Delete(key string) error }
type TokenBucket ¶
type TokenBucket struct { Used float64 LastAccessTime time.Time Limit float64 Duration time.Duration }
func NewTokenBucket ¶
func NewTokenBucket(limit float64, duration time.Duration) *TokenBucket
func (*TokenBucket) Consume ¶
func (bucket *TokenBucket) Consume(count float64) error
func (*TokenBucket) GetAdjustedUsage ¶
func (bucket *TokenBucket) GetAdjustedUsage(now time.Time) float64
Source Files ¶
Click to show internal directories.
Click to hide internal directories.