()
| 49 | } |
| 50 | |
| 51 | func 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 | |
| 70 | func PortFree(port string) bool { |
| 71 | log.Debugf("Checking if port %s is free", port) |
nothing calls this directly
no test coverage detected