Fill out port 80 if it's available, otherwise port 3000

This commit is contained in:
Eugene Bujak
2019-02-01 18:18:08 +03:00
parent 34e14930de
commit d97c426646
2 changed files with 27 additions and 4 deletions

View File

@@ -258,6 +258,16 @@ func findIPv4IfaceAddr(ifaces []netInterface) string {
return ""
}
// checkPortAvailable is not a cheap test to see if the port is bindable, because it's actually doing the bind momentarily
func checkPortAvailable(port int) bool {
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
return false
}
ln.Close()
return true
}
// ---------------------
// debug logging helpers
// ---------------------