Help us shape the future of Go! Take the 2026 Go Developer Survey

netutil

package
v1.0.109 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 9 Imported by: 7

Documentation

Overview

Package netutil provides free port discovery, local IP, node info, and URL parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFreePort

func FindFreePort(host string, maxAttempts int) (int, error)

FindFreePort returns a free port found on a host

func GetLocalIP

func GetLocalIP() (string, error)

GetLocalIP returns the non loopback local IP of the host

func IsAddrInUse

func IsAddrInUse(err error) bool

IsAddrInUse checks whether the given error indicates "address in use"

func IsPrivateAddress deprecated

func IsPrivateAddress(address string) (bool, error)

IsPrivateAddress reports whether address is loopback, link-local, or RFC1918/ULA.

Deprecated: use net.ParseIP(address) with net.IP.IsPrivate, IsLoopback, and IsLinkLocalUnicast. IsPrivate does not treat loopback or link-local as private; this helper does.

func JoinURLs

func JoinURLs(list []*url.URL) string

JoinURLs returns coma-separated lists of URLs in string format

func ParseURLs

func ParseURLs(list []string) ([]*url.URL, error)

ParseURLs creates a list of URLs from lists of hosts

func ParseURLsFromString

func ParseURLsFromString(hosts string) ([]*url.URL, error)

ParseURLsFromString creates a list of URLs from a coma-separated lists of hosts

func WaitForNetwork

func WaitForNetwork(d time.Duration) (ipaddr string, err error)

WaitForNetwork will wait until the local IP is available or timeout ocurred

Types

type GetNodeNameFn

type GetNodeNameFn func(hostname string) string

GetNodeNameFn is an interface to return an application specific node name from the host name.

type NodeInfo

type NodeInfo interface {
	HostName() string
	LocalIP() string
	NodeName() string
}

NodeInfo is an interface to provide host and IP address for the node in the cluster.

func NewNodeInfo

func NewNodeInfo(extractor GetNodeNameFn) (NodeInfo, error)

NewNodeInfo constructs node info using provided extractor function. If extractor is nil, then host name is used.

Jump to

Keyboard shortcuts

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