Documentation ¶
Index ¶
- Constants
- Variables
- type BucketContainer
- func (b *BucketContainer) CreateBucketIfNotExists(user string)
- func (b *BucketContainer) Drain(amount int8, user string) error
- func (b *BucketContainer) Get(user string) int8
- func (b *BucketContainer) HasKeys(user string) bool
- func (b *BucketContainer) Init()
- func (b *BucketContainer) Refiller()
- func (b *BucketContainer) Set(user string, value int8)
Constants ¶
View Source
const ( // How many keys a bucket may contain when created BUCKET_INITIAL_FILL = 64 // The maximum amount of keys a user may possess BUCKET_UPPER_BOUND = 64 // How often new keys drip into the buckets DROP_INTERVAL = 10 * time.Second // How many keys may drop at a time DROP_SIZE = 3 )
Variables ¶
View Source
var Container = &BucketContainer{}
Global pointer to a container instance
Functions ¶
This section is empty.
Types ¶
type BucketContainer ¶
Container struct to lock the bucket map
func (*BucketContainer) CreateBucketIfNotExists ¶
func (b *BucketContainer) CreateBucketIfNotExists(user string)
Check if the user has a bucket. If not create one
func (*BucketContainer) Drain ¶
func (b *BucketContainer) Drain(amount int8, user string) error
Drains $amount from $user if he has enough keys left
func (*BucketContainer) Get ¶
func (b *BucketContainer) Get(user string) int8
func (*BucketContainer) HasKeys ¶
func (b *BucketContainer) HasKeys(user string) bool
Check if the user still has keys
func (*BucketContainer) Init ¶
func (b *BucketContainer) Init()
Allocates the map and starts routines
func (*BucketContainer) Refiller ¶
func (b *BucketContainer) Refiller()
Refills user buckets in a set interval
func (*BucketContainer) Set ¶
func (b *BucketContainer) Set(user string, value int8)
Click to show internal directories.
Click to hide internal directories.