From 1a693fec05e5b9c723496824e3c33b041f8859ef Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 21 Oct 2017 17:07:25 +0200 Subject: [PATCH] Minor changes --- middleware/UserInfo.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/middleware/UserInfo.go b/middleware/UserInfo.go index f2888793..2a3e825f 100644 --- a/middleware/UserInfo.go +++ b/middleware/UserInfo.go @@ -1,17 +1,16 @@ package middleware import ( - "encoding/json" "net/http" "strconv" "strings" "github.com/aerogo/aero" + "github.com/aerogo/http/client" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/utils" "github.com/fatih/color" "github.com/mssola/user_agent" - "github.com/parnurzeal/gorequest" ) // UserInfo updates user related information after each request. @@ -73,21 +72,20 @@ func updateUserInfo(ctx *aero.Context, user *arn.User) { func updateUserLocation(user *arn.User, newIP string) { user.IP = newIP locationAPI := "https://api.ipinfodb.com/v3/ip-city/?key=" + arn.APIKeys.IPInfoDB.ID + "&ip=" + user.IP + "&format=json" + response, err := client.Get(locationAPI).End() - response, data, err := gorequest.New().Get(locationAPI).EndBytes() - - if len(err) > 0 && err[0] != nil { - color.Red("Couldn't fetch location data | Error: %s | IP: %s", err[0].Error(), user.IP) + if err != nil { + color.Red("Couldn't fetch location data | Error: %s | IP: %s", err.Error(), user.IP) return } - if response.StatusCode != http.StatusOK { + if response.StatusCode() != http.StatusOK { color.Red("Couldn't fetch location data | Status: %d | IP: %s", response.StatusCode, user.IP) return } newLocation := arn.IPInfoDBLocation{} - json.Unmarshal(data, &newLocation) + response.Unmarshal(&newLocation) if newLocation.CountryName != "-" { user.Location.CountryName = newLocation.CountryName