(startPort, maxPort int)
| 8 | ) |
| 9 | |
| 10 | func FindAvailablePort(startPort, maxPort int) (int, error) { |
| 11 | for port := startPort; port <= maxPort; port++ { |
| 12 | if IsPortAvailable(port) { |
| 13 | log.Printf("Port %d is available!", port) |
| 14 | return port, nil |
| 15 | } |
| 16 | } |
| 17 | return 0, fmt.Errorf("no available ports found in range %d-%d", startPort, maxPort) |
| 18 | } |
| 19 | |
| 20 | func IsPortAvailable(port int) bool { |
| 21 | timeout := time.Second |
no test coverage detected