From 5e15abaf52a47f8f3550b137c8ca60598333ddc6 Mon Sep 17 00:00:00 2001 From: showwin Date: Tue, 19 Apr 2016 21:22:10 +0900 Subject: [PATCH] add error handle when www.speedtest.net/speedtest-config.php is unavailable --- user.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/user.go b/user.go index c63a2ff..ef726b9 100644 --- a/user.go +++ b/user.go @@ -42,10 +42,16 @@ func fetchUserInfo() User { decoder.DecodeElement(&users, &se) } } + if users.Users == nil { + fmt.Println("Warning: Cannot fetch user information. http://www.speedtest.net/speedtest-config.php is temporarily unavailable.") + return User{} + } return users.Users[0] } // Show user location func (u *User) Show() { - fmt.Println("Testing From IP: " + u.IP + " (" + u.Isp + ") [" + u.Lat + ", " + u.Lon + "]") + if u.IP != "" { + fmt.Println("Testing From IP: " + u.IP + " (" + u.Isp + ") [" + u.Lat + ", " + u.Lon + "]") + } }