-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- changed getHostByName - added unit-test
- Loading branch information
lib0xidium
committed
Oct 10, 2024
1 parent
fc7fc0d
commit 65d69fd
Showing
2 changed files
with
39 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
package sprig | ||
|
||
import ( | ||
"math/rand" | ||
"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(nil) | ||
for tries := 0; tries < NUM_TRIES; tries++ { | ||
if addrs, err = net.LookupHost(name); err == nil { | ||
return addrs, nil | ||
} | ||
} | ||
return addrs, err | ||
} |
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