优化服务启动流程

This commit is contained in:
2025-05-14 15:13:44 +08:00
parent d69a77df38
commit f86cf47e86
7 changed files with 243 additions and 123 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/pkg/errors"
"net/http"
"strings"
)
func Ipapi() (prov, city, isp string, err error) {
@@ -31,7 +32,49 @@ func Ipapi() (prov, city, isp string, err error) {
prov = data.RegionName
city = data.City
isp = data.As
var telecom = []string{"AS4134", "AS4812", "AS134419", "AS140292"}
var unicom = []string{"AS4837", "AS17621", "AS17816"}
var mobile = []string{
"AS9808", "AS24444", "AS24445", "AS24547", "AS38019",
"AS56040", "AS56041", "AS56042", "AS56044", "AS56046", "AS56047",
"AS132525", "AS134810",
}
var foreign = []string{
"AS9299",
}
for _, telecomAsn := range telecom {
if strings.HasPrefix(data.As, telecomAsn) {
isp = "电信"
break
}
}
if isp == "" {
for _, unicomAsn := range unicom {
if strings.HasPrefix(data.As, unicomAsn) {
isp = "联通"
break
}
}
}
if isp == "" {
for _, mobileAsn := range mobile {
if strings.HasPrefix(data.As, mobileAsn) {
isp = "移动"
break
}
}
}
if isp == "" {
for _, foreignAsn := range foreign {
if strings.HasPrefix(data.As, foreignAsn) {
isp = "国外"
break
}
}
}
if prov == "" || city == "" || isp == "" {
return "", "", "", errors.New("解析数据为空")
}