hoster/internals/helpers/port.go

21 lines
292 B
Go
Raw Permalink Normal View History

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
}