mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-07 08:06:37 +08:00
fix(openflare): mmdb 国家名节点在世界地图使用正确质心
- 从 world-geo 生成国家质心表,Server 在仅有 ISO/国家名时补全 geo 坐标 - 全球态势板在缺少经纬度时按 geo_name 解析质心,避免 fallback 到美国
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Rain-kl/Wavelet/internal/model"
|
||||
pkggeoip "github.com/Rain-kl/Wavelet/pkg/geoip"
|
||||
"github.com/Rain-kl/Wavelet/pkg/logger"
|
||||
)
|
||||
|
||||
@@ -40,7 +41,26 @@ func ApplyNodeGeoFromIP(ctx context.Context, node *model.OpenFlareNode, rawIP st
|
||||
if info.Latitude != nil && info.Longitude != nil {
|
||||
node.GeoLatitude = cloneCoordinate(info.Latitude)
|
||||
node.GeoLongitude = cloneCoordinate(info.Longitude)
|
||||
return
|
||||
}
|
||||
applyCountryCentroid(node, info.ISOCode, info.Name)
|
||||
}
|
||||
|
||||
func applyCountryCentroid(node *model.OpenFlareNode, isoCode, name string) {
|
||||
if lat, lon, ok := pkggeoip.CountryCentroidByISO(isoCode); ok {
|
||||
node.GeoLatitude = cloneFloat(lat)
|
||||
node.GeoLongitude = cloneFloat(lon)
|
||||
return
|
||||
}
|
||||
if lat, lon, ok := pkggeoip.CountryCentroidByName(name); ok {
|
||||
node.GeoLatitude = cloneFloat(lat)
|
||||
node.GeoLongitude = cloneFloat(lon)
|
||||
}
|
||||
}
|
||||
|
||||
func cloneFloat(value float64) *float64 {
|
||||
cloned := value
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneCoordinate(value *float64) *float64 {
|
||||
|
||||
Reference in New Issue
Block a user