Add flags to customize listen ports and detect port collisions

This commit is contained in:
Manuel de Brito Fontes 2017-08-24 10:33:26 -03:00
parent 02e20eb81a
commit 0459674931
12 changed files with 127 additions and 47 deletions

View file

@ -17,7 +17,9 @@ limitations under the License.
package main
import (
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"syscall"
@ -74,3 +76,12 @@ func diff(b1, b2 []byte) ([]byte, error) {
out, _ := exec.Command("diff", "-u", f1.Name(), f2.Name()).CombinedOutput()
return out, nil
}
func isPortAvailable(p int) bool {
ln, err := net.Listen("tcp", fmt.Sprintf(":%v", p))
if err != nil {
return false
}
ln.Close()
return true
}