Make sure port is actually free and show what port was used.

This commit is contained in:
2024-09-11 11:14:27 +02:00
parent e276649fc5
commit e7ed0407a3
6 changed files with 255 additions and 102 deletions

20
internals/helpers/port.go Normal file
View 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
}