Fix country flag with code for chat room
This commit is contained in:
parent
0c5db949aa
commit
79a6b8048c
|
@ -98,7 +98,7 @@ func Landing() http.HandlerFunc {
|
|||
}
|
||||
|
||||
// Country flag emoji.
|
||||
emoji, err := geoip.GetRequestCountryFlag(r)
|
||||
emoji, err := geoip.GetRequestCountryFlagWithCode(r)
|
||||
if err != nil {
|
||||
emoji, err = geoip.CountryFlagEmojiWithCode("US")
|
||||
if err != nil {
|
||||
|
|
|
@ -36,6 +36,21 @@ func GetRequestCountryFlag(r *http.Request) (string, error) {
|
|||
return CountryFlagEmoji(city.Country.IsoCode)
|
||||
}
|
||||
|
||||
// GetRequestCountryFlagWithCode returns the flag joined with the country code by a space (like CountryFlagEmojiWithCode).
|
||||
func GetRequestCountryFlagWithCode(r *http.Request) (string, error) {
|
||||
city, err := GetRequestCity(r)
|
||||
if err != nil {
|
||||
// If the remote addr is localhost (local dev testing), default to US flag.
|
||||
if addr := utility.IPAddress(r); addr == "127.0.0.1" || addr == "::1" {
|
||||
return CountryFlagEmojiWithCode("US")
|
||||
}
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
return CountryFlagEmojiWithCode(city.Country.IsoCode)
|
||||
}
|
||||
|
||||
// GetCity queries the GeoIP database for city information for an IP address.
|
||||
func GetCity(ip net.IP) (*geoip2.City, error) {
|
||||
db, err := geoip2.Open(config.GeoIPPath)
|
||||
|
|
Loading…
Reference in New Issue
Block a user