diff --git a/network.go b/network.go index 108d78a..f144087 100644 --- a/network.go +++ b/network.go @@ -5,8 +5,15 @@ import ( "net" ) -func getHostByName(name string) string { - addrs, _ := net.LookupHost(name) - //TODO: add error handing when release v3 comes out - return addrs[rand.Intn(len(addrs))] +const NUM_TRIES = 3 + +func getHostByName(name string) (string, error) { + err := error(nil) + addrs := []string{} + for tries := NUM_TRIES; tries > 0; tries-- { + if addrs, err = net.LookupHost(name); err == nil { + return addrs[rand.Intn(len(addrs))], nil + } + } + return "", err }