This is a more up-to-date hard fork of https://github.com/phayes/freeport
It has phayes#8 merged, the CLI removed (Go package only), and other minor improvements.
PRs welcome and appreciated.
package main
import "github.com/slimsag/freeport"
func main() {
port, err := freeport.GetFreePort()
if err != nil {
log.Fatal(err)
}
// port should be ready to listen on
}