<fixed>fixed bugs that ipinfo db using different symbol for country iso.

This commit is contained in:
2025-12-28 17:40:15 +00:00
parent 3fcfe1eaf1
commit 0eb104a2d6
2 changed files with 14 additions and 8 deletions

BIN
dashboard

Binary file not shown.

View File

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