ratelimit

package
v0.0.0-...-adbe570 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MillitokensPerSecond

type MillitokensPerSecond uint64

type TokenBucket

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

A token bucket rate limiter. Can store at most UINT32_MAX tokens before it saturates. The zero TokenBucket{} is a valid value.

NOT thread-safe

func NewTokenBucket

func NewTokenBucket(rate MillitokensPerSecond, capacity uint32, full bool) *TokenBucket

func (*TokenBucket) AddTokens

func (tb *TokenBucket) AddTokens(n uint32)

Adds n tokens to the bucket.

func (*TokenBucket) Capacity

func (tb *TokenBucket) Capacity() uint32

func (*TokenBucket) Rate

func (tb *TokenBucket) Rate() MillitokensPerSecond

func (*TokenBucket) RemoveTokens

func (tb *TokenBucket) RemoveTokens(n uint32) bool

Removes n tokens from the bucket. If the bucket contained at least n tokens, return true. Otherwise, returns false and sets bucket to contain zero tokens.

func (*TokenBucket) SetCapacity

func (tb *TokenBucket) SetCapacity(capacity uint32)

Sets the bucket's capacity.

func (*TokenBucket) SetRate

func (tb *TokenBucket) SetRate(rate MillitokensPerSecond)

Sets the rate at which the bucket fills with tokens.

Jump to

Keyboard shortcuts

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