Documentation
¶
Overview ¶
Package net provides network utilities extending the standard net package.
Index ¶
- func FreePort(ctx context.Context) (int, error)
- func FreePorts(ctx context.Context, n int) ([]int, error)
- func IsFreePort(ctx context.Context, port int) error
- func WaitFor(ctx context.Context, network, address string, timeout time.Duration) error
- func WaitForFreePort(ctx context.Context, port int, timeout time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FreePort ¶
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
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
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.
Types ¶
This section is empty.