func lookupCountry(db *geoip2.Reader, ip net.IP) (string, error) { if db == nil { return "", nil } record, err := db.Country(ip) if err != nil { return "", err } if country, exists := record.Country.Names["en"]; exists { return country, nil } if country, exists := record.RegisteredCountry.Names["en"]; exists { return country, nil } return "", fmt.Errorf("could not determine country for IP: %s", ip) }