net

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 6 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package net provides network utilities extending the standard net package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreePort

func FreePort(ctx context.Context) (int, error)

FreePort returns a port on localhost that is currently unused, by briefly binding to port 0 and releasing it. The port can be claimed by another process before the caller uses it.

func FreePorts added in v0.11.0

func FreePorts(ctx context.Context, n int) ([]int, error)

FreePorts returns n distinct ports on localhost that are currently unused, by briefly binding to n separate port-0 listeners and releasing them all. It returns nil, nil if n <= 0. The ports can be claimed by another process before the caller uses them.

func IsFreePort added in v0.11.0

func IsFreePort(ctx context.Context, port int) error

IsFreePort reports whether port is currently unused on localhost, by attempting to bind to it and immediately releasing it. It returns a non-nil error if the port is already in use or cannot be bound.

func WaitFor added in v0.11.0

func WaitFor(ctx context.Context, network, address string, timeout time.Duration) error

WaitFor attempts to establish a connection to the specified address until the timeout or context cancellation occurs.

func WaitForFreePort added in v0.11.0

func WaitForFreePort(ctx context.Context, port int, timeout time.Duration) error

WaitForFreePort attempts to establish a TCP connection to the specified address until the timeout or context cancellation occurs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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