diff --git a/dashboard b/dashboard deleted file mode 100755 index a8d3037..0000000 Binary files a/dashboard and /dev/null differ diff --git a/pkg/geoip/geoip.go b/pkg/geoip/geoip.go index 6559db3..4c06bbd 100644 --- a/pkg/geoip/geoip.go +++ b/pkg/geoip/geoip.go @@ -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")