From dbecfd880d1435458cea9ae6d17da9ca896ee7fa Mon Sep 17 00:00:00 2001 From: sjlleo Date: Wed, 25 May 2022 17:19:54 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E9=A3=8E=E6=8E=A7IP=E4=BC=9A?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E9=80=80=E5=87=BA=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ipgeo/ipgeo.go | 4 +++- ipgeo/ipsb.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ipgeo/ipgeo.go b/ipgeo/ipgeo.go index 0de5b71..be2ea19 100644 --- a/ipgeo/ipgeo.go +++ b/ipgeo/ipgeo.go @@ -1,6 +1,8 @@ package ipgeo -import "strings" +import ( + "strings" +) type IPGeoData struct { Asnumber string diff --git a/ipgeo/ipsb.go b/ipgeo/ipsb.go index 8bee301..aca919b 100644 --- a/ipgeo/ipsb.go +++ b/ipgeo/ipsb.go @@ -2,6 +2,7 @@ package ipgeo import ( "io/ioutil" + "log" "net/http" "time" @@ -11,7 +12,7 @@ import ( func IPSB(ip string) (*IPGeoData, error) { url := "https://api.ip.sb/geoip/" + ip client := &http.Client{ - // 2秒超时 + // 2 秒超时 Timeout: 2 * time.Second, } req, _ := http.NewRequest("GET", url, nil) @@ -19,6 +20,7 @@ func IPSB(ip string) (*IPGeoData, error) { req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0") content, err := client.Do(req) if err != nil { + log.Println("api.ip.sb 请求超时(2s),请切换其他API使用") return nil, err } body, _ := ioutil.ReadAll(content.Body)