1 Commits
1.0.0 ... 1.0.1

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