Created
July 18, 2018 16:46
-
-
Save lysu/c18d9a9f7816bf4fe651e97b91f3fa92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getLocalAddr(machines []string) (string, error) { | |
for _, m := range machines { | |
conn, err := net.Dial("udp", m) | |
if err != nil { | |
continue | |
} | |
defer conn.Close() | |
return strings.Split(conn.LocalAddr().String(), ":")[0], nil | |
} | |
return "", errors.New("no reachable machine to get local addr") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment