find ip info
(ipORdomain string)
| 80 | |
| 81 | // find ip info |
| 82 | func (g GeoIP) Find(ipORdomain string) (ip, country string, err error) { |
| 83 | ips, err := net.LookupIP(ipORdomain) |
| 84 | if err != nil { |
| 85 | return "", "", err |
| 86 | } |
| 87 | ip = ips[0].String() |
| 88 | |
| 89 | var record *geoip2.City |
| 90 | record, err = g.db.City(ips[0]) |
| 91 | if err != nil { |
| 92 | return |
| 93 | } |
| 94 | countryIsoCode := record.Country.IsoCode |
| 95 | if countryIsoCode == "" { |
| 96 | country = fmt.Sprintf("🏁 ZZ") |
| 97 | } |
| 98 | emoji, found := g.emojiMap[countryIsoCode] |
| 99 | if found { |
| 100 | country = fmt.Sprintf("%v %v", emoji, countryIsoCode) |
| 101 | } else { |
| 102 | country = fmt.Sprintf("🏁 ZZ") |
| 103 | } |
| 104 | return |
| 105 | } |
no test coverage detected