Add: Server location latitude and longitude

This commit is contained in:
EUForest
2025-11-04 14:53:43 +08:00
parent 2fd119d697
commit 52ce054b35
12 changed files with 2700 additions and 58 deletions
+2524
View File
File diff suppressed because it is too large Load Diff
+15 -7
View File
@@ -74,6 +74,12 @@ func GetRegionByIp(ip string) (*GeoLocationResponse, error) {
if response.Country == "" {
continue
}
response.LatitudeCenter, response.LongitudeCenter, _ = GetCapitalCoordinates(fmt.Sprintf("%s,%s", response.Country, response.City))
if response.LatitudeCenter == "" || response.LongitudeCenter == "" {
response.LatitudeCenter = response.Latitude
response.LongitudeCenter = response.Longitude
}
return response, nil
}
}
@@ -181,11 +187,13 @@ func decompressResponse(resp *http.Response) ([]byte, error) {
// GeoLocationResponse represents the geolocation data returned by the API.
type GeoLocationResponse struct {
Country string `json:"country"`
CountryName string `json:"country_name"`
Region string `json:"region"`
City string `json:"city"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
Loc string `json:"loc"`
Country string `json:"country"`
CountryName string `json:"country_name"`
Region string `json:"region"`
City string `json:"city"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
LatitudeCenter string `json:"latitude_center"`
LongitudeCenter string `json:"longitude_center"`
Loc string `json:"loc"`
}