mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-07 04:20:12 +02:00
fix(publicip/api/ip2location): rename countries to match standard country names
This commit is contained in:
@@ -8,18 +8,21 @@ import (
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type ip2Location struct {
|
||||
client *http.Client
|
||||
token string
|
||||
client *http.Client
|
||||
token string
|
||||
countryCodes map[string]string
|
||||
}
|
||||
|
||||
func newIP2Location(client *http.Client, token string) *ip2Location {
|
||||
return &ip2Location{
|
||||
client: client,
|
||||
token: token,
|
||||
client: client,
|
||||
token: token,
|
||||
countryCodes: constants.CountryCodes(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +98,24 @@ func (i *ip2Location) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||
return result, fmt.Errorf("decoding response: %w", err)
|
||||
}
|
||||
|
||||
// Remove parentheses from country name
|
||||
idx := strings.Index(data.CountryName, " (")
|
||||
if idx != -1 {
|
||||
data.CountryName = data.CountryName[:idx]
|
||||
}
|
||||
|
||||
// Rename country to match country string obtained from other IP data sources
|
||||
countryRenames := map[string]string{
|
||||
"Netherlands": i.countryCodes["nl"],
|
||||
"United States of America": i.countryCodes["us"],
|
||||
"United Kingdom of Great Britain and Northern Ireland": i.countryCodes["gb"],
|
||||
"Czechia": i.countryCodes["cz"],
|
||||
"Korea": i.countryCodes["kr"],
|
||||
}
|
||||
if newName, ok := countryRenames[data.CountryName]; ok {
|
||||
data.CountryName = newName
|
||||
}
|
||||
|
||||
result = models.PublicIP{
|
||||
IP: data.IP,
|
||||
Region: data.RegionName,
|
||||
|
||||
Reference in New Issue
Block a user