From 8fc8cf2d39a26c93662775f05510e2b6be43fb7c Mon Sep 17 00:00:00 2001 From: i3h Date: Sun, 24 May 2020 02:18:36 +0000 Subject: [PATCH] Change Query API New Query API is https://ifconfig.is/json The IP data is provided by MaxMind. --- log.go | 15 +++++++++++++-- query.go | 16 ++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/log.go b/log.go index fdeaa1d..74adce2 100644 --- a/log.go +++ b/log.go @@ -83,11 +83,22 @@ func logQuery(info IPInfo) { values := make([]string, v.NumField()) for i := 0; i < v.NumField(); i++ { names[i] = v.Type().Field(i).Name - values[i] = v.Field(i).Interface().(string) + t := v.Field(i).Type().Name() + if t == "string" { + values[i] = v.Field(i).Interface().(string) + } else if t == "bool" { + values[i] = strconv.FormatBool(v.Field(i).Interface().(bool)) + } else if t == "float64" { + values[i] = fmt.Sprintf("%f", v.Field(i).Interface().(float64)) + } else if t == "uint" { + values[i] = fmt.Sprint(v.Field(i).Interface().(uint)) + } } l := getMaxNameLength(names) for i := 0; i < v.NumField(); i++ { - fmt.Printf("%s: %s\n", cyan("%-*s", l, names[i]), values[i]) + if values[i] != "" { + fmt.Printf("%s: %s\n", cyan("%-*s", l, names[i]), values[i]) + } } } diff --git a/query.go b/query.go index 8c64cbd..ebdb771 100644 --- a/query.go +++ b/query.go @@ -9,15 +9,19 @@ import ( ) const ( - API string = "http://ip-api.com/json/" + API string = "https://ifconfig.is/json/" ) type IPInfo struct { - IP string `json:"query"` - City string `json:"city"` - Country string `json:"country"` - ISP string `json:"isp"` - AS string `json:"as"` + Continent string `json:"Continent"` + Country string `json:"Country"` + City string `json:"City"` + Latitude float64 `json:"Latitude"` + Longitude float64 `json:"Longitude"` + TimeZone string `json:"TimeZone"` + IsEU bool `json:"IsEU"` + ASN uint `json:"ASN"` + ORG string `json:"ORG"` } func queryInfo(address string) IPInfo {