freeport

package
v0.0.0-...-5fb8a3f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocateTCPPort

func AllocateTCPPort() (uint16, io.Closer, error)

AllocateTCPPort allocates a TCP port on the looopback address, and starts a temporary listener on it. That listener is returned to the caller alongside with the allocated port number. The listener must be closed right before the port is used by the caller. This naturally still leaves a race condition window where that port number might be snatched up by some other process, but there doesn't seem to be a better way to do this.

func MustConsume

func MustConsume(port uint16, lis io.Closer, err error) int

MustConsume takes the result of AllocateTCPPort, closes the listener and returns the allocated port. If anything goes wrong (port could not be allocated or closed) it will panic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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