portallocator

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPortRange invalid port range
	ErrInvalidPortRange = errors.New("Invalid port range")
	// ErrNoPortLeft no port left in the range
	ErrNoPortLeft = errors.New("No free port left")
)

Functions

This section is empty.

Types

type PortAllocator

type PortAllocator struct {
	insanelock.RWMutex
	MinPort int
	MaxPort int
	PortMap map[int]bool
}

PortAllocator describes a threads safe port list that can be allocated

func New

func New(min, max int) (*PortAllocator, error)

New creates a new port allocator range

func (*PortAllocator) Allocate

func (p *PortAllocator) Allocate(fnc func(int) error) (int, error)

Allocate returns a new port between min and max ports. Call the given function that will validate the allocation

func (*PortAllocator) Release

func (p *PortAllocator) Release(i int) error

Release a port

func (*PortAllocator) ReleaseAll

func (p *PortAllocator) ReleaseAll()

ReleaseAll ports

Jump to

Keyboard shortcuts

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