limiter

package
v0.0.0-...-29bfbee Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SHARDS = uint64(1024)

Functions

func TimeTrack

func TimeTrack(start time.Time, name string)

Types

type Bucket

type Bucket struct {
	Value        int64
	WillBeFullAt int64
	UpdatedAt    int64
}

type RateLimiter

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

func NewRateLimiter

func NewRateLimiter() *RateLimiter

func (*RateLimiter) CleanUpFullBuckets

func (l *RateLimiter) CleanUpFullBuckets()

func (*RateLimiter) GetShard

func (l *RateLimiter) GetShard(key int64) *Shard

func (*RateLimiter) Len

func (l *RateLimiter) Len() int64

func (*RateLimiter) Reduce

func (l *RateLimiter) Reduce(key string, maxTokens int64, refillTime int64, refillAmount int64, tokens int64) (int64, error)

func (*RateLimiter) Remove

func (l *RateLimiter) Remove(key string)

func (*RateLimiter) StartCleanUpFullBuckets

func (l *RateLimiter) StartCleanUpFullBuckets()

type Shard

type Shard struct {
	Buckets map[string]Bucket
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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