update: 完善一下 ipapicom

This commit is contained in:
sjlleo
2022-05-27 17:18:31 +08:00
parent 4eaac372f6
commit 84c48dae99
2 changed files with 9 additions and 7 deletions

View File

@@ -1,11 +1,11 @@
package ipgeo
import (
"errors"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"regexp"
"time"
"github.com/tidwall/gjson"
@@ -27,12 +27,14 @@ func IPApiCom(ip string) (*IPGeoData, error) {
body, _ := ioutil.ReadAll(content.Body)
res := gjson.ParseBytes(body)
if res.Get("country").String() == "" {
os.Exit(1)
if res.Get("status").String() != "success" {
return &IPGeoData{}, errors.New("超过API阈值")
}
log.Println("ip-api.com 正在使用")
re := regexp.MustCompile("[0-9]+")
return &IPGeoData{
Asnumber: strings.Split(res.Get("as").String(), " ")[0],
Asnumber: re.FindString(res.Get("as").String()),
Country: res.Get("country").String(),
City: res.Get("city").String(),
Prov: res.Get("regionName").String(),

View File

@@ -24,7 +24,7 @@ func GetSource(s string) Source {
return IPSB
case "IPINSIGHT":
return IPInSight
case "ip-api.com":
case "IPAPI.COM":
return IPApiCom
default:
return nil