limiter

package
v1.32.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyedBytesLimiter

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

KeyedBytesLimiter tracks in-flight bytes and enforces a global total plus a per-key sub-limit, so one key cannot exhaust the whole total. The limits are supplied by the caller on each reservation, so the limiter itself holds no configuration and only does the accounting. It is safe for concurrent use.

func NewKeyedBytesLimiter

func NewKeyedBytesLimiter() *KeyedBytesLimiter

NewKeyedBytesLimiter returns an empty limiter.

func (*KeyedBytesLimiter) Release

func (l *KeyedBytesLimiter) Release(key string, n int64) int64

Release returns n bytes for the given key and reports the resulting global total.

func (*KeyedBytesLimiter) TryReserve

func (l *KeyedBytesLimiter) TryReserve(key string, n, totalLimit, keyLimit int64) (bool, int64)

TryReserve adds n bytes to the totals if both the global total stays within totalLimit and the key's total within keyLimit. A non-positive limit disables that check. Returns success and the resulting global total.

func (*KeyedBytesLimiter) Used

func (l *KeyedBytesLimiter) Used() int64

Used reports the current global in-flight byte total.

Jump to

Keyboard shortcuts

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