limiter

package
v1.29.4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 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 BandwidthLimit

type BandwidthLimit struct {
	UploadBytesPerSecond   *int64 `yaml:"upload,omitempty"`
	DownloadBytesPerSecond *int64 `yaml:"download,omitempty"`
}

BandwidthLimit represents bandwidth limit configuration

type BandwidthLimiter

type BandwidthLimiter interface {
	CheckUpload(clientId string, bytes int64) bool
	CheckDownload(clientId string, bytes int64) bool
	SetClientLimit(clientId string, limit *BandwidthLimit)
	RemoveClientLimit(clientId string)
}

BandwidthLimiter interface for bandwidth limiting operations

func NewBandwidthLimiter

func NewBandwidthLimiter(limits *ClientBandwidthLimits) BandwidthLimiter

NewBandwidthLimiter creates a new bandwidth limiter

type ClientBandwidthLimits

type ClientBandwidthLimits struct {
	ByClientId map[string]*BandwidthLimit
	Global     *BandwidthLimit
}

ClientBandwidthLimits contains bandwidth limits configuration

type TokenBucket

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

TokenBucket implements a token bucket for rate limiting

func NewTokenBucket

func NewTokenBucket(capacity float64, refillRate float64) *TokenBucket

NewTokenBucket creates a new token bucket

func (*TokenBucket) CanConsume

func (tb *TokenBucket) CanConsume(tokens float64) bool

CanConsume checks if there are enough tokens (without consuming)

func (*TokenBucket) Consume

func (tb *TokenBucket) Consume(tokens float64) bool

Consume tries to consume the specified number of tokens

func (*TokenBucket) GetAvailableTokens

func (tb *TokenBucket) GetAvailableTokens() float64

GetAvailableTokens returns the current number of available tokens

Jump to

Keyboard shortcuts

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