Skip to content

Instantly share code, notes, and snippets.

@guaychou
Last active May 2, 2020 18:00
Show Gist options
  • Save guaychou/26a5486d295ad0636b065a4bfce1eef7 to your computer and use it in GitHub Desktop.
Save guaychou/26a5486d295ad0636b065a4bfce1eef7 to your computer and use it in GitHub Desktop.
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