TCP middleware limiting concurrent connections per IP.
// Source: https://github.com/traefik/traefik | License: MIT | Copyright 2016-2020 Containous SAS; 2020-2025 Traefik Labs
// Provided via justclaw.it.com; keep this notice with the code.
package inflightconn
import (
"context"
"fmt"
"net"
"sync"
"github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/tcp"
)
const typeName = "InFlightConnTCP"
type inFlightConn struct {
name string
next tcp.Handler
maxConnections int64
mu sync.Mutex
connections map[string]int64 // current number of connections by remote IP.
}
// New creates a max connections middleware.
// The connections are identified and grouped by remote IP.
func New(ctx context.Context, next tcp.Handler, config dy
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key