mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
<fixed>fixed bugs that ipinfo db using different symbol for country iso.
This commit is contained in:
@@ -24,10 +24,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type IPInfo struct {
|
type IPInfo struct {
|
||||||
Country string `maxminddb:"country"`
|
// 对应数据库里的 "country_code" 字段 (例如 "CN")
|
||||||
CountryName string `maxminddb:"country_name"`
|
CountryCode string `maxminddb:"country_code"`
|
||||||
Continent string `maxminddb:"continent"`
|
|
||||||
ContinentName string `maxminddb:"continent_name"`
|
// 对应数据库里的 "continent_code" 字段 (例如 "AS")
|
||||||
|
ContinentCode string `maxminddb:"continent_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Lookup(ip net.IP) (string, error) {
|
func Lookup(ip net.IP) (string, error) {
|
||||||
@@ -42,10 +43,15 @@ func Lookup(ip net.IP) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if record.Country != "" {
|
// 1. 优先返回 CountryCode (如 "cn")
|
||||||
return strings.ToLower(record.Country), nil
|
if record.CountryCode != "" {
|
||||||
} else if record.Continent != "" {
|
// 前端依然需要小写才能匹配 flags/cn.svg
|
||||||
return strings.ToLower(record.Continent), nil
|
return strings.ToLower(record.CountryCode), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 其次返回 ContinentCode
|
||||||
|
if record.ContinentCode != "" {
|
||||||
|
return strings.ToLower(record.ContinentCode), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", errors.New("IP not found")
|
return "", errors.New("IP not found")
|
||||||
|
|||||||
Reference in New Issue
Block a user