Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultPortChecker(port int) bool
- func Provide(i *do.Injector)
- type ErrNotInRange
- type PortChecker
- type PortRange
- func (r *PortRange) Allocate(port int) error
- func (r *PortRange) AllocateNext() (int, error)
- func (r *PortRange) ForEach(fn func(int))
- func (r *PortRange) Free() int
- func (r *PortRange) Has(port int) bool
- func (r *PortRange) Release(port int) error
- func (r *PortRange) Restore(data []byte) error
- func (r *PortRange) Snapshot() []byte
- func (r *PortRange) Used() int
- type Service
- type Store
- func (s *Store) ExistsByKey(allocatorName string) storage.ExistsOp
- func (s *Store) GetByKey(allocatorName string) storage.GetOp[*StoredPortRange]
- func (s *Store) Key(allocatorName string) string
- func (s *Store) Prefix() string
- func (s *Store) Update(item *StoredPortRange) storage.PutOp[*StoredPortRange]
- type StoredPortRange
Constants ¶
const ( MinValidPort = 1 MaxValidPort = 65535 )
Variables ¶
var ( ErrFull = errors.New("range is full") ErrAllocated = errors.New("provided port is already allocated") )
Functions ¶
func DefaultPortChecker ¶
DefaultPortChecker returns true if the given TCP port is not currently bound by any process on the local host.
Types ¶
type ErrNotInRange ¶
func (*ErrNotInRange) Error ¶
func (e *ErrNotInRange) Error() string
type PortChecker ¶
PortChecker reports whether a port is available for binding.
type PortRange ¶
type PortRange struct {
// contains filtered or unexported fields
}
PortRange tracks allocated ports across the full valid range [1, 65535] using a big.Int bitmap, where bit N represents port N. Random allocation draws only from [min, max], but any port in [1, 65535] can be recorded via Allocate. This means min and max can be reconfigured without affecting previously stored state.
func NewPortRange ¶
NewPortRange creates a PortRange for the given spec.
func (*PortRange) Allocate ¶
Allocate reserves the given port. Any port in [1, 65535] may be recorded, including ports outside [min, max]. ErrAllocated is returned if the port is already reserved.
func (*PortRange) AllocateNext ¶
AllocateNext reserves a random unallocated port from [min, max]. ErrFull is returned if all ports in the range are allocated.
func (*PortRange) ForEach ¶
ForEach calls fn for every allocated port across the full valid range [1, 65535].
func (*PortRange) Release ¶
Release clears the port's allocated bit. Out-of-range or unallocated ports are silently ignored.
func (*PortRange) Restore ¶
Restore loads a previously saved bitmap. The spec in specStr must be valid JSON, but a min/max mismatch does not cause an error — the current range's min/max are preserved, allowing the configuration to be changed without losing allocation history.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) AllocatePort ¶
AllocatePort allocates the next available port in [min, max] that is not already recorded in the persistent range and is not currently bound on the local host.
func (*Service) ReleasePort ¶
ReleasePort releases the given port back to the pool, persisting the updated state to storage.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) GetByKey ¶
func (s *Store) GetByKey(allocatorName string) storage.GetOp[*StoredPortRange]
func (*Store) Update ¶
func (s *Store) Update(item *StoredPortRange) storage.PutOp[*StoredPortRange]
type StoredPortRange ¶
type StoredPortRange struct {
storage.StoredValue
Name string `json:"name"`
Snapshot []byte `json:"snapshot"`
}