Skip to content

Commit

Permalink
feat: geoip use default lang when selected not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Dec 21, 2023
1 parent 214d935 commit a1f4690
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/geoip/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func (g GeoIP) Find(query string, params ...string) (result fmt.Stringer, err er
}

result = Result{
Country: record.Country.Names[lang],
Country: getMapLang(record.Country.Names, lang),
CountryCode: record.Country.IsoCode,
Area: record.City.Names[lang],
Area: getMapLang(record.City.Names, lang),
}
return
}
Expand All @@ -72,3 +72,13 @@ func (r Result) String() string {
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]
}

0 comments on commit a1f4690

Please sign in to comment.