randomports

package
v0.0.0-...-e9f60da Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package randomports provides helpers to get random, free port numbers for testing listener use cases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reserve

func Reserve(p Port) bool

Reserve puts the port into a shared cache. When the port exist, false is returned (as in it could not reserve the port for you to vend).

func Two

func Two() (Port, Port, error)

Two provides a set of ports. For convenience.

Types

type Port

type Port uint16

Port holds a port number value. This type provides a convenient handle on that port number across a few different use cases.

func One

func One() (Port, error)

One provides a single port. For convenience.

func RandomPorts

func RandomPorts(n int) ([]Port, error)

RandomPorts returns a list of port numbers that are safe-to-assume to be free. An internal list is used track vended ports to avoid concurrent users from seeing conflicting ports.

func (Port) Int

func (p Port) Int() int

Int returns the port as an int.

func (*Port) Must

func (p *Port) Must() *Port

Must is a builder style conditional that can be used to ensure (by panic) that a port number is given (ie: not 0).

func (Port) String

func (p Port) String() string

String prints the port number as a string.

func (Port) Uint

func (p Port) Uint() uint

Uint returns the port as an uint.

func (Port) Uint16

func (p Port) Uint16() uint16

Uint16 returns the port as an uint16.

Jump to

Keyboard shortcuts

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