Free Port finder using Golang
package main
import (
"fmt"
"github.com/gort"
)
func main(){
tcpPort, err := gort.GetFreePort()
if err != nil{
fmt.Println(fmt.Sprintf("Fatal error: %s", err.Error()))
}
fmt.Println(tcpPort)
}
Once the gort is built using go build
, use the executable as
$ gort
$ SOME_PORT_NUMBER_PRINTED