From 1d709a3446b27748cb7691506c354d4b0ef45404 Mon Sep 17 00:00:00 2001 From: jiacai_wang Date: Sun, 19 Sep 2021 21:13:13 +0800 Subject: [PATCH] simplify json fields. --- alidns.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/alidns.go b/alidns.go index 9b21ad7..f4d75e9 100644 --- a/alidns.go +++ b/alidns.go @@ -26,20 +26,9 @@ type Config struct { } type IpJson struct { - Status string `json:"status"` - Country string `json:"country"` - CountryCode string `json:"countryCode"` - Region string `json:"region"` - RegionName string `json:"regionName"` - City string `json:"city"` - Zip string `json:"zip"` - Lat float64 `json:"lat"` - Lon float64 `json:"lon"` - Timezone string `json:"timezone"` - Isp string `json:"isp"` - Org string `json:"org"` - As string `json:"as"` - Query string `json:"query"` + Status string `json:"status"` + Message string `json:"message"` + Query string `json:"query"` } func main() { @@ -55,7 +44,7 @@ func main() { var config Config json.Unmarshal(configJson, &config) - res, err := http.Get("http://ip-api.com/json/") + res, err := http.Get("http://ip-api.com/json?fields=status,message,query") if err != nil { log.Fatal(err) } @@ -69,7 +58,7 @@ func main() { json.Unmarshal(data, &ipJson) ip := ipJson.Query if ipJson.Status != "success" { - log.Fatal("get ip failed") + log.Fatal("get ip failed: " + ipJson.Message) } client, err := alidns.NewClientWithAccessKey(config.RegionId, config.AccessKeyId, config.AccessSecret)