ports

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAvailablePort

func FindAvailablePort(checker PortChecker, startPort int, maxAttempts int) int

FindAvailablePort finds the first available port starting from startPort. It searches up to maxAttempts ports.

func ResetCache

func ResetCache()

ResetCache clears the port availability cache. Used for testing.

Types

type MockPortChecker

type MockPortChecker struct {
	AvailablePorts map[int]bool
}

MockPortChecker is a test implementation that can be configured.

func (MockPortChecker) IsAvailable

func (m MockPortChecker) IsAvailable(port int) bool

type PortChecker

type PortChecker interface {
	IsAvailable(port int) bool
}

PortChecker defines the interface for checking port availability.

type RealPortChecker

type RealPortChecker struct{}

RealPortChecker uses net.Listen to check port availability.

func (RealPortChecker) IsAvailable

func (RealPortChecker) IsAvailable(port int) bool

IsAvailable checks if a TCP port is available on localhost. It uses net.Listen to attempt binding to the port.

Jump to

Keyboard shortcuts

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