MCPcopy Create free account
hub / github.com/cnshym/httpgo / GetRandomPort

Function GetRandomPort

pkg/utils/random.go:25–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25func GetRandomPort() (int, error) {
26 // Listen on a random port
27 addr, err := net.Listen("tcp", ":0")
28 if err != nil {
29 return 0, err
30 }
31 defer addr.Close()
32 port := addr.Addr().(*net.TCPAddr).Port
33 return port, nil
34}

Callers 1

mainFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected