Documentation
¶
Index ¶
- type MemoryStorage
- func (ms *MemoryStorage) Count(bucketName string) (int, error)
- func (ms *MemoryStorage) Create(name string, capacity int) error
- func (ms *MemoryStorage) Ping() error
- func (ms *MemoryStorage) Put(bucketName string, tokens int) error
- func (ms *MemoryStorage) Set(bucketName string, tokens int) error
- func (ms *MemoryStorage) Take(bucketName string, tokens int) error
- func (ms *MemoryStorage) TakeAll(bucketName string) (int, error)
- type RedisStorage
- func (rs *RedisStorage) Count(bucketName string) (int, error)
- func (rs *RedisStorage) Create(name string, capacity int) error
- func (rs *RedisStorage) Ping() error
- func (rs *RedisStorage) Put(bucketName string, tokens int) error
- func (rs *RedisStorage) Set(bucketName string, tokens int) error
- func (rs *RedisStorage) Take(bucketName string, tokens int) error
- func (rs *RedisStorage) TakeAll(bucketName string) (int, error)
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
Implement an in-memory datastore with a concurrent safe map protected by a RWmutex
func (*MemoryStorage) Count ¶
func (ms *MemoryStorage) Count(bucketName string) (int, error)
We only need a read lock here because we are only reading it.
func (*MemoryStorage) Create ¶
func (ms *MemoryStorage) Create(name string, capacity int) error
Create an entry in the map if one does not exist for the given name. If an entry already exists return nil so that the bucket will share the entry.
func (*MemoryStorage) Ping ¶
func (ms *MemoryStorage) Ping() error
func (*MemoryStorage) Put ¶
func (ms *MemoryStorage) Put(bucketName string, tokens int) error
Increment the entry value by the given tokens integer
func (*MemoryStorage) Take ¶
func (ms *MemoryStorage) Take(bucketName string, tokens int) error
Decrement the entry value unless the value < tokens. If value < tokens return an error else return nil. Note that we don't check if name exists as a key of the map, this is because storage.Take is called directly from it's parent method on Bucket where the name is derived from. A bucket can't exist to call if it doesn't already have a name...
type RedisStorage ¶
func (*RedisStorage) Count ¶
func (rs *RedisStorage) Count(bucketName string) (int, error)
Return the token value of a given bucket.
func (*RedisStorage) Create ¶
func (rs *RedisStorage) Create(name string, capacity int) error
bucket.Create will create a new bucket with the given parameters if one does not exist, if no bucket can be created it will return an error
func (*RedisStorage) Ping ¶
func (rs *RedisStorage) Ping() error
func (*RedisStorage) Put ¶
func (rs *RedisStorage) Put(bucketName string, tokens int) error
Increment the token value by a given amount.
type Storage ¶
type Storage interface { Ping() error Create(name string, tokens int) error Take(bucketName string, tokens int) error TakeAll(bucketName string) (int, error) Set(bucketName string, tokens int) error Put(bucketName string, tokens int) error Count(bucketName string) (int, error) }
Interface for storage providers. I know the 'I' prefix isn't Golang convention but I prefer it.