浏览文件
port.go
19 行 · 339 B历史下载| 1 | package e2eutils |
| 2 | |
| 3 | import ( |
| 4 | "net" |
| 5 | "strconv" |
| 6 | ) |
| 7 | |
| 8 | func IsPortAvailable(port int) bool { |
| 9 | return IsHostPortAvailable("127.0.0.1", port) |
| 10 | } |
| 11 | |
| 12 | func IsHostPortAvailable(host string, port int) bool { |
| 13 | listener, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port))) |
| 14 | if err != nil { |
| 15 | return false |
| 16 | } |
| 17 | listener.Close() |
| 18 | return true |
| 19 | } |

