Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter bounds concurrent executions using a buffered channel semaphore.
func NewLimiter ¶
NewLimiter creates a limiter with the provided capacity.
func (*Limiter) Acquire ¶
Acquire reserves an execution slot or returns when the context is canceled.
func (*Limiter) TryAcquire ¶ added in v0.4.0
TryAcquire reserves an execution slot without blocking. It returns false when all slots are in use.
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
TokenBucket is a non-blocking token bucket rate limiter.
Tokens are refilled continuously at refillRate tokens per second up to capacity. Each call to Allow consumes one token if available and returns true; otherwise it returns false immediately without blocking.
The caller controls the clock by passing the current time to Allow, which makes the bucket deterministic and easy to test.
func NewDrainedTokenBucket ¶
func NewDrainedTokenBucket(capacity int, refillRate float64) *TokenBucket
NewDrainedTokenBucket is like NewTokenBucket but starts with zero tokens. Refill rate and capacity are unchanged; emissions pace from the first Allow instead of consuming an initial full bucket in one burst.
func NewTokenBucket ¶
func NewTokenBucket(capacity int, refillRate float64) *TokenBucket
NewTokenBucket creates a full token bucket with the given capacity and refill rate (tokens per second).
Panics if capacity <= 0 or refillRate <= 0.
func (*TokenBucket) Allow ¶
func (tb *TokenBucket) Allow(now time.Time) bool
Allow refills tokens based on elapsed time since the last call, then consumes one token if available. It returns true when the request is allowed, false when the bucket is empty.
now must be monotonically non-decreasing across calls from the same goroutine; passing a time earlier than the previous call is a no-op for the refill step (elapsed is clamped to zero).
func (*TokenBucket) SetRefillRate ¶
func (tb *TokenBucket) SetRefillRate(rate float64, now time.Time)
SetRefillRate applies refill from lastRefill to now at the current rate, then switches the bucket to rate for future refills. Tokens stay capped at capacity.
Panics if rate <= 0, consistent with NewTokenBucket.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ssrf provides an opt-in policy that rejects HTTP requests to private, link-local, and cloud-metadata IP ranges before they leave the process.
|
Package ssrf provides an opt-in policy that rejects HTTP requests to private, link-local, and cloud-metadata IP ranges before they leave the process. |