ratelimits

package
v0.0.0-...-07de05f Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

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

type BucketContainer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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)

Jump to

Keyboard shortcuts

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