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.