Make sure port is actually free and show what port was used.
This commit is contained in:
20
internals/helpers/port.go
Normal file
20
internals/helpers/port.go
Normal file
@ -0,0 +1,20 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
func IsFreePort(port int) bool {
|
||||
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("localhost:%d", port))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
l, err := net.ListenTCP("tcp", addr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer l.Close()
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user