Documentation
¶
Overview ¶
Package portalloc provides a central port allocator for Gopherstack services. Services that expose real network endpoints (e.g., ElastiCache, Lambda function URLs) can request a dedicated port from the pool and release it when the resource is deleted.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidRange = errors.New("invalid port range: start must be ≥ 1 and end > start")
ErrInvalidRange is returned when the port range is invalid.
var ErrNoPortsAvailable = errors.New("no ports available in range")
ErrNoPortsAvailable is returned when the pool has no free ports.
var ErrPortNotAllocated = errors.New("port not allocated")
ErrPortNotAllocated is returned when trying to release a port that was not allocated.
Functions ¶
func IsListening ¶
IsListening performs a TCP health check on the given address to detect zombie listeners — ports that are allocated but no longer serving connections. Returns true if a listener is detected.
Types ¶
type Allocator ¶
type Allocator struct {
// contains filtered or unexported fields
}
Allocator manages a pool of ports within a configurable range. It is safe for concurrent use.
func New ¶
New creates a new Allocator for the half-open range [start, end). start must be ≥ 1 and end must be > start.
func (*Allocator) Acquire ¶
Acquire returns the next free port in the range and associates it with label. Returns ErrNoPortsAvailable when the pool is exhausted.
func (*Allocator) Allocated ¶
Allocated returns a snapshot of all currently allocated ports and their labels.
func (*Allocator) IsAllocated ¶
IsAllocated reports whether port is currently allocated.