1FreePort
2========
3
4Get a free open TCP port that is ready to use.
5
6## Command Line Example:
7```bash
8# Ask the kernel to give us an open port.
9export port=$(freeport)
10
11# Start standalone httpd server for testing
12httpd -X -c "Listen $port" &
13
14# Curl local server on the selected port
15curl localhost:$port
16```
17
18## Golang example:
19```go
20package main
21
22import "github.com/phayes/freeport"
23
24func main() {
25 port, err := freeport.GetFreePort()
26 if err != nil {
27 log.Fatal(err)
28 }
29 // port is ready to listen on
30}
31
32```
33
34## Installation
35
36#### CentOS and other RPM based systems
37```bash
38wget https://github.com/phayes/freeport/releases/download/0.1.2/freeport_0.1.2_linux_386.rpm
39rpm -Uvh freeport_0.1.2_linux_386.rpm
40```
41
42#### Ubuntu and other DEB based systems
43```bash
44wget wget https://github.com/phayes/freeport/releases/download/0.1.2/freeport_0.1.2_linux_amd64.deb
45dpkg -i freeport_0.1.2_linux_amd64.deb
46```
47
48## Building From Source
49```bash
50sudo apt-get install golang # Download go. Alternativly build from source: https://golang.org/doc/install/source
51mkdir ~/.gopath && export GOPATH=~/.gopath # Replace with desired GOPATH
52export PATH=$PATH:$GOPATH/bin # For convenience, add go's bin dir to your PATH
53go get github.com/phayes/freeport/cmd/freeport
54```