Last active
May 2, 2020 18:00
-
-
Save guaychou/26a5486d295ad0636b065a4bfce1eef7 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 pingGoogle() (string,error) { | |
pinger,err := ping.NewPinger("www.google.com") | |
if err != nil { | |
return "", errors.New("Network Error") | |
} | |
pinger.Count = 1 | |
pinger.Timeout=2 * time.Second | |
pinger.Debug=true | |
pinger.Run() | |
if pinger.Statistics().Rtts==nil{ | |
return "",errors.New("Network Error") | |
} | |
return strconv.Itoa(int(pinger.Statistics().Rtts[0].Milliseconds())) +" ms",nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment