Documentation
¶
Overview ¶
Package conn implements connection limiters that control the number of concurrent connections per key (global, per-IP, or per-CIDR). Limits can be loaded from static configuration, files, Redis, or HTTP endpoints with periodic hot-reload support.
Index ¶
- Constants
- func NewConnLimiter(opts ...Option) limiter.ConnLimiter
- func NewLimiter(n int) limiter.Limiter
- type ConnLimitGenerator
- 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 ( // GlobalLimitKey is the special key for a global connection limit that applies // to all connections regardless of their source IP. GlobalLimitKey = "$" // IPLimitKey is the special key for a per-IP connection limit that applies // as a default when no specific IP or CIDR rule matches. IPLimitKey = "$$" )
Variables ¶
This section is empty.
Functions ¶
func NewConnLimiter ¶
func NewConnLimiter(opts ...Option) limiter.ConnLimiter
NewConnLimiter creates a new ConnLimiter with the given options. It starts a background goroutine for periodic reload of limit rules.
func NewLimiter ¶
NewLimiter creates a Limiter that allows up to n concurrent connections.
Types ¶
type ConnLimitGenerator ¶
ConnLimitGenerator creates individual Limiter instances for use in per-IP or per-CIDR connection limiting.
func NewConnLimitGenerator ¶
func NewConnLimitGenerator(n int) ConnLimitGenerator
NewConnLimitGenerator returns a ConnLimitGenerator that creates a new Limiter on each call to Limiter(), using the given limit n.
func NewConnLimitSingleGenerator ¶
func NewConnLimitSingleGenerator(n int) ConnLimitGenerator
NewConnLimitSingleGenerator returns a ConnLimitGenerator that always returns the same Limiter instance, using the given limit n.
type Option ¶
type Option func(opts *options)
func FileLoaderOption ¶
FileLoaderOption sets the file loader for reading limit rules from a file.
func HTTPLoaderOption ¶
HTTPLoaderOption sets the HTTP loader for reading limit rules from an HTTP endpoint.
func LimitsOption ¶
LimitsOption sets the static limit rules. Each rule is a string in the form "key limit", e.g. "192.168.1.0/24 100".
func LoggerOption ¶
LoggerOption sets the logger for the connection limiter.
func RedisLoaderOption ¶
RedisLoaderOption sets the Redis loader for reading limit rules from Redis.
func ReloadPeriodOption ¶
ReloadPeriodOption sets the period for hot-reloading limit rules from external loaders (file, Redis, HTTP). A period <= 0 disables periodic reload.