network

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllAddresses

func AllAddresses() ([]net.IP, error)

func GetFreePort

func GetFreePort() (int, error)

GetFreePort returns a single available port by asking the operating system to pick one for us. Luckily ports are not re-used so after asking for a port number, we attempt to create a tcp listener.

Essentially the same code as https://github.com/phayes/freeport but we bind to 0.0.0.0 to ensure the port is free on all interfaces, and not just localhost.GetFreePort Ports must be unique for an address, not an entire system and so checking just localhost is not enough.

func GetFreePorts

func GetFreePorts(count int) ([]int, error)

GetFreePorts returns an array available ports by asking the operating system to pick one for us.

Essentially the same code as https://github.com/phayes/freeport apart from the caveats described in GetFreePort.

func GetNetworkAddress

func GetNetworkAddress(requested AddressType, getAddresses AddressLister) ([]string, error)

GetNetworkAddress returns a list of network addresses of the requested type, sourcing the addresses from the provided AddressLister. It is expected that network.AddAddresses() will be the default address lister. The result is a list of strings representing the network addresses in the order they were returned by the AddressLister.

func IsPortOpen added in v1.3.0

func IsPortOpen(port int) bool

IsPortOpen checks if a port is open by attempting to listen on it. If the port is open, it returns true, otherwise it returns false. The port listen socket will be closed if the function was able to create it.

Types

type AddressLister

type AddressLister func() ([]net.IP, error)

type AddressType

type AddressType int
const (
	PrivateAddress AddressType = iota
	PublicAddress
	LoopbackAddress
	LinkLocal
	Multicast
	Any
)

func AddressTypeFromString

func AddressTypeFromString(t string) (AddressType, bool)

func (AddressType) String

func (a AddressType) String() string

Jump to

Keyboard shortcuts

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