mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-03 20:20:10 +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 {
|
||||
Country string `maxminddb:"country"`
|
||||
CountryName string `maxminddb:"country_name"`
|
||||
Continent string `maxminddb:"continent"`
|
||||
ContinentName string `maxminddb:"continent_name"`
|
||||
// 对应数据库里的 "country_code" 字段 (例如 "CN")
|
||||
CountryCode string `maxminddb:"country_code"`
|
||||
|
||||
// 对应数据库里的 "continent_code" 字段 (例如 "AS")
|
||||
ContinentCode string `maxminddb:"continent_code"`
|
||||
}
|
||||
|
||||
func Lookup(ip net.IP) (string, error) {
|
||||
@@ -42,10 +43,15 @@ func Lookup(ip net.IP) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if record.Country != "" {
|
||||
return strings.ToLower(record.Country), nil
|
||||
} else if record.Continent != "" {
|
||||
return strings.ToLower(record.Continent), nil
|
||||
// 1. 优先返回 CountryCode (如 "cn")
|
||||
if record.CountryCode != "" {
|
||||
// 前端依然需要小写才能匹配 flags/cn.svg
|
||||
return strings.ToLower(record.CountryCode), nil
|
||||
}
|
||||
|
||||
// 2. 其次返回 ContinentCode
|
||||
if record.ContinentCode != "" {
|
||||
return strings.ToLower(record.ContinentCode), nil
|
||||
}
|
||||
|
||||
return "", errors.New("IP not found")
|
||||
|
||||
Reference in New Issue
Block a user