freeport

package module
v0.0.0-...-74d24b5 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: BSD-3-Clause Imports: 1 Imported by: 425 modules, 420 packages

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.

README

FreePort

Get a free open TCP port that is ready to use.

Command Line Example:

# Ask the kernel to give us an open port.
export port=$(freeport)

# Start standalone httpd server for testing
httpd -X -c "Listen $port" &

# Curl local server on the selected port
curl localhost:$port

Golang example:

package main

import "github.com/phayes/freeport"

func main() {
	port, err := freeport.GetFreePort()
	if err != nil {
		log.Fatal(err)
	}
	// port is ready to listen on
}

Installation

Mac OSX
brew install phayes/repo/freeport
CentOS and other RPM based systems
wget https://github.com/phayes/freeport/releases/download/1.0.2/freeport_1.0.2_linux_386.rpm
rpm -Uvh freeport_1.0.2_linux_386.rpm
Ubuntu and other DEB based systems
wget wget https://github.com/phayes/freeport/releases/download/1.0.2/freeport_1.0.2_linux_amd64.deb
dpkg -i freeport_1.0.2_linux_amd64.deb
Building From Source
sudo apt-get install golang                    # Download go. Alternativly build from source: https://golang.org/doc/install/source
go get github.com/phayes/freeport

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func GetFreePorts

func GetFreePorts(count int) ([]int, error)

GetFreePort asks the kernel for free open ports that are ready to use.

func GetPort

func GetPort() int

GetPort is deprecated, use GetFreePort instead Ask the kernel for a free open port that is ready to use

Types

This section is empty.

Directories

Path Synopsis
cmd
freeport command

Jump to

Keyboard shortcuts

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