21 lines
292 B
Go
21 lines
292 B
Go
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
|
|
}
|