conn

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func NewLimiter(n int) limiter.Limiter

NewLimiter creates a Limiter that allows up to n concurrent connections.

Types

type ConnLimitGenerator

type ConnLimitGenerator interface {
	Limiter() limiter.Limiter
}

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

func FileLoaderOption(fileLoader loader.Loader) Option

FileLoaderOption sets the file loader for reading limit rules from a file.

func HTTPLoaderOption

func HTTPLoaderOption(httpLoader loader.Loader) Option

HTTPLoaderOption sets the HTTP loader for reading limit rules from an HTTP endpoint.

func LimitsOption

func LimitsOption(limits ...string) Option

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

func LoggerOption(logger logger.Logger) Option

LoggerOption sets the logger for the connection limiter.

func RedisLoaderOption

func RedisLoaderOption(redisLoader loader.Loader) Option

RedisLoaderOption sets the Redis loader for reading limit rules from Redis.

func ReloadPeriodOption

func ReloadPeriodOption(period time.Duration) Option

ReloadPeriodOption sets the period for hot-reloading limit rules from external loaders (file, Redis, HTTP). A period <= 0 disables periodic reload.

Directories

Path Synopsis
Package wrapper provides net.Conn and net.Listener wrappers that enforce connection limits.
Package wrapper provides net.Conn and net.Listener wrappers that enforce connection limits.

Jump to

Keyboard shortcuts

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