update: 风控IP会直接退出,避免没有数据

This commit is contained in:
sjlleo
2022-05-25 17:19:54 +08:00
parent a67a4bc559
commit dbecfd880d
2 changed files with 6 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
package ipgeo
import "strings"
import (
"strings"
)
type IPGeoData struct {
Asnumber string

View File

@@ -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)