mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
feat: geoip use default lang when selected not exist
This commit is contained in:
parent
214d935a25
commit
a1f4690e72
@ -48,9 +48,9 @@ func (g GeoIP) Find(query string, params ...string) (result fmt.Stringer, err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = Result{
|
result = Result{
|
||||||
Country: record.Country.Names[lang],
|
Country: getMapLang(record.Country.Names, lang),
|
||||||
CountryCode: record.Country.IsoCode,
|
CountryCode: record.Country.IsoCode,
|
||||||
Area: record.City.Names[lang],
|
Area: getMapLang(record.City.Names, lang),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -72,3 +72,13 @@ func (r Result) String() string {
|
|||||||
return fmt.Sprintf("%s %s", r.Country, r.Area)
|
return fmt.Sprintf("%s %s", r.Country, r.Area)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DefaultLang = "en"
|
||||||
|
|
||||||
|
func getMapLang(data map[string]string, lang string) string {
|
||||||
|
res, found := data[lang]
|
||||||
|
if found {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
return data[DefaultLang]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user