MCPcopy Create free account
hub / github.com/bytesizedhosting/bcd / GetFreePort

Function GetFreePort

core/helpers.go:51–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49}
50
51func GetFreePort() (string, error) {
52 rand.Seed(time.Now().UnixNano())
53
54 log.Debugln("Attempting to get a free port")
55
56 tries := 0
57 for tries < 10 {
58 port := strconv.Itoa(rand.Intn(50000) + 1024)
59 log.Debugf("Claimed port %d", port)
60
61 if PortFree(port) {
62 return port, nil
63 }
64
65 tries++
66 }
67 return "", errors.New("Could not find free port.")
68}
69
70func PortFree(port string) bool {
71 log.Debugf("Checking if port %s is free", port)

Callers

nothing calls this directly

Calls 1

PortFreeFunction · 0.85

Tested by

no test coverage detected