mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-01 14:46:36 +08:00
fix(openflare): Agent 上报 IP 后由 Server 自动解析节点地理位置
- 启动时按 of_options.GeoIPProvider 初始化 pkg/geoip(bootstrap + runtime) - mmdb 模式从内置 GeoLite2 种子到 data/;保存归属方式后热刷新 Provider - Agent/Relay 心跳在服务端根据 IP 写入 geo 字段,尊重 geo_manual_override - ipinfo 归属名称改为 City, Region, Country 可读格式
This commit is contained in:
+19
-1
@@ -81,9 +81,10 @@ func (s *IPInfoService) GetGeoInfo(ip net.IP) (*GeoInfo, error) {
|
||||
// 实际上,IPinfo 的 'country' 字段就是 ISO 2-letter code。
|
||||
// 如果需要完整的国家名称,可能需要一个本地的 ISO 代码到名称的映射。
|
||||
// 为了与 GetRegionUnicodeEmoji 函数兼容,我们直接使用 country 作为 ISOCode。
|
||||
name := formatIPInfoLocation(apiResp)
|
||||
return &GeoInfo{
|
||||
ISOCode: apiResp.Country,
|
||||
Name: apiResp.Country,
|
||||
Name: name,
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
}, nil
|
||||
@@ -115,3 +116,20 @@ func parseIPInfoCoordinates(value string) (*float64, *float64) {
|
||||
|
||||
return float64Pointer(latitudeValue), float64Pointer(longitudeValue)
|
||||
}
|
||||
|
||||
func formatIPInfoLocation(resp ipInfoResponse) string {
|
||||
parts := make([]string, 0, 3)
|
||||
if city := strings.TrimSpace(resp.City); city != "" {
|
||||
parts = append(parts, city)
|
||||
}
|
||||
if region := strings.TrimSpace(resp.Region); region != "" {
|
||||
parts = append(parts, region)
|
||||
}
|
||||
if country := strings.TrimSpace(resp.Country); country != "" {
|
||||
parts = append(parts, country)
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
return ""
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user