mirror of
https://github.com/oarkflow/mq.git
synced 2025-10-16 20:00:39 +08:00
update: HTTP API
This commit is contained in:
@@ -13,3 +13,17 @@ func ConnectionsEqual(c1, c2 net.Conn) bool {
|
||||
}
|
||||
return localAddr(c1) == localAddr(c2) && remoteAddr(c1) == remoteAddr(c2)
|
||||
}
|
||||
|
||||
// GetRandomPort returns a free port chosen by the operating system.
|
||||
func GetRandomPort() (int, error) {
|
||||
// Bind to port 0, which instructs the OS to assign an available port.
|
||||
ln, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
// Extract the port number from the listener's address.
|
||||
addr := ln.Addr().(*net.TCPAddr)
|
||||
return addr.Port, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user