Documentation
¶
Overview ¶
Package traffic provides a traffic/bandwidth limiter implementation that supports per-service, per-connection, per-IP, and per-CIDR rate limiting for both ingress (In) and egress (Out) directions.
Index ¶
- Constants
- func NewLimiter(r int) limiter.Limiter
- func NewLimiterWithBurst(r, burst int) limiter.Limiter
- func NewTrafficLimiter(opts ...Option) traffic.TrafficLimiter
- type Option
- func FileLoaderOption(fileLoader loader.Loader) Option
- func HTTPLoaderOption(httpLoader loader.Loader) Option
- func LimitsOption(limits ...string) Option
- func LoggerOption(logger logger.Logger) Option
- func RedisLoaderOption(redisLoader loader.Loader) Option
- func ReloadPeriodOption(period time.Duration) Option
Constants ¶
const ( // ServiceLimitKey is the special key used for service-level rate limits. ServiceLimitKey = "$" // ConnLimitKey is the special key used for connection-level rate limits. ConnLimitKey = "$$" )
Variables ¶
This section is empty.
Functions ¶
func NewLimiter ¶
NewLimiter creates a rate-based traffic Limiter with the given rate (bytes per second). The burst size is set equal to the rate.
func NewLimiterWithBurst ¶ added in v0.28.1
NewLimiterWithBurst creates a rate-based traffic Limiter with the given rate (bytes per second) and burst size. If burst <= 0, it defaults to r.
func NewTrafficLimiter ¶
func NewTrafficLimiter(opts ...Option) traffic.TrafficLimiter
NewTrafficLimiter creates a new TrafficLimiter with the given options. It starts a background goroutine for periodic reload of limit rules from external loaders.
Types ¶
type Option ¶
type Option func(opts *options)
Option configures a TrafficLimiter.
func FileLoaderOption ¶
FileLoaderOption sets a file-based loader for limit rules.
func HTTPLoaderOption ¶
HTTPLoaderOption sets an HTTP-based loader for limit rules.
func LimitsOption ¶
LimitsOption sets the static limit rules. Each string is a limit definition in the format "<key> <in> [out]" where in/out are byte quantities with optional SI/IEC suffixes (e.g., "100B", "1MB", "512KB").
func LoggerOption ¶
LoggerOption sets the logger for the traffic limiter.
func RedisLoaderOption ¶
RedisLoaderOption sets a Redis-based loader for limit rules.
func ReloadPeriodOption ¶
ReloadPeriodOption sets the period for reloading limit rules from external loaders. A period of zero disables periodic reloading.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package limiter provides a cached traffic limiter that wraps a TrafficLimiter with in-memory caching to reduce calls to the underlying limiter (e.g., plugin-based limiters).
|
Package limiter provides a cached traffic limiter that wraps a TrafficLimiter with in-memory caching to reduce calls to the underlying limiter (e.g., plugin-based limiters). |
|
Package wrapper provides net.Conn, net.PacketConn, and io.ReadWriter wrappers that apply traffic rate limiting to reads and writes.
|
Package wrapper provides net.Conn, net.PacketConn, and io.ReadWriter wrappers that apply traffic rate limiting to reads and writes. |