diff --git a/apiserver/api.go b/apiserver/api.go index 2a1ff92..6bd8edb 100644 --- a/apiserver/api.go +++ b/apiserver/api.go @@ -231,15 +231,16 @@ func (q *geoipQuery) Record(ip net.IP, lang string) *responseRecord { lang = parseAcceptLanguage(lang, q.Country.Names) r := &responseRecord{ - IP: ip.String(), - CountryCode: q.Country.ISOCode, - CountryName: q.Country.Names[lang], - City: q.City.Names[lang], - ZipCode: q.Postal.Code, - TimeZone: q.Location.TimeZone, - Latitude: roundFloat(q.Location.Latitude, .5, 4), - Longitude: roundFloat(q.Location.Longitude, .5, 4), - MetroCode: q.Location.MetroCode, + IP: ip.String(), + IsInEuropeanUnion: q.Country.IsInEuropeanUnion, + CountryCode: q.Country.ISOCode, + CountryName: q.Country.Names[lang], + City: q.City.Names[lang], + ZipCode: q.Postal.Code, + TimeZone: q.Location.TimeZone, + Latitude: roundFloat(q.Location.Latitude, .5, 4), + Longitude: roundFloat(q.Location.Longitude, .5, 4), + MetroCode: q.Location.MetroCode, } if len(q.Region) > 0 { r.RegionCode = q.Region[0].ISOCode @@ -285,24 +286,29 @@ func roundFloat(val float64, roundOn float64, places int) (newVal float64) { } type responseRecord struct { - XMLName xml.Name `xml:"Response" json:"-"` - IP string `json:"ip"` - CountryCode string `json:"country_code"` - CountryName string `json:"country_name"` - RegionCode string `json:"region_code"` - RegionName string `json:"region_name"` - City string `json:"city"` - ZipCode string `json:"zip_code"` - TimeZone string `json:"time_zone"` - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - MetroCode uint `json:"metro_code"` + XMLName xml.Name `xml:"Response" json:"-"` + IP string `json:"ip"` + IsInEuropeanUnion bool `json:"is_in_european_union"` + CountryCode string `json:"country_code"` + CountryName string `json:"country_name"` + RegionCode string `json:"region_code"` + RegionName string `json:"region_name"` + City string `json:"city"` + ZipCode string `json:"zip_code"` + TimeZone string `json:"time_zone"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + MetroCode uint `json:"metro_code"` } func (rr *responseRecord) String() string { b := &bytes.Buffer{} w := csv.NewWriter(b) w.UseCRLF = true + var inEU int + if rr.IsInEuropeanUnion { + inEU = 1 + } w.Write([]string{ rr.IP, rr.CountryCode, @@ -315,6 +321,7 @@ func (rr *responseRecord) String() string { strconv.FormatFloat(rr.Latitude, 'f', 4, 64), strconv.FormatFloat(rr.Longitude, 'f', 4, 64), strconv.Itoa(int(rr.MetroCode)), + strconv.Itoa(inEU), }) w.Flush() return b.String() diff --git a/db.go b/db.go index 2810a7e..b5689f0 100644 --- a/db.go +++ b/db.go @@ -414,8 +414,9 @@ type DefaultQuery struct { Names map[string]string `maxminddb:"names"` } `maxminddb:"continent"` Country struct { - ISOCode string `maxminddb:"iso_code"` - Names map[string]string `maxminddb:"names"` + ISOCode string `maxminddb:"iso_code"` + IsInEuropeanUnion bool `maxminddb:"is_in_european_union"` + Names map[string]string `maxminddb:"names"` } `maxminddb:"country"` Region []struct { ISOCode string `maxminddb:"iso_code"`