wip
This commit is contained in:
17
networking/freePort.go
Normal file
17
networking/freePort.go
Normal file
@ -0,0 +1,17 @@
|
||||
package net
|
||||
|
||||
import "net"
|
||||
|
||||
func GetFreeTcpPort() (int, error) {
|
||||
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
l, err := net.ListenTCP("tcp", addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer l.Close()
|
||||
return l.Addr().(*net.TCPAddr).Port, nil
|
||||
}
|
3
networking/go.mod
Normal file
3
networking/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module gitea.codeblob.work/pk/gut/networking
|
||||
|
||||
go 1.22.0
|
Reference in New Issue
Block a user