diff --git a/http/http.go b/http/http.go index 44eda00..7accf96 100644 --- a/http/http.go +++ b/http/http.go @@ -31,15 +31,15 @@ type Server struct { } type Response struct { - IP net.IP `json:"ip"` - IPDecimal *big.Int `json:"ip_decimal"` - Country string `json:"country,omitempty"` - CountryISO string `json:"country_iso,omitempty"` - City string `json:"city,omitempty"` - Hostname string `json:"hostname,omitempty"` - IsInEuropeanUnion bool `json:"is_in_european_union,omitempty"` - Latitude float64 `json:"location_latitude,omitempty"` - Longitude float64 `json:"location_longitude,omitempty"` + IP net.IP `json:"ip"` + IPDecimal *big.Int `json:"ip_decimal"` + Country string `json:"country,omitempty"` + CountryEU bool `json:"country_eu,omitempty"` + CountryISO string `json:"country_iso,omitempty"` + City string `json:"city,omitempty"` + Hostname string `json:"hostname,omitempty"` + Latitude float64 `json:"latitude,omitempty"` + Longitude float64 `json:"longitude,omitempty"` } type PortResponse struct { @@ -98,15 +98,15 @@ func (s *Server) newResponse(r *http.Request) (Response, error) { hostname, _ = s.LookupAddr(ip) } return Response{ - IP: ip, - IPDecimal: ipDecimal, - Country: country.Name, - CountryISO: country.ISO, - IsInEuropeanUnion: country.IsInEuropeanUnion, - City: city.Name, - Hostname: hostname, - Latitude: city.Latitude, - Longitude: city.Longitude, + IP: ip, + IPDecimal: ipDecimal, + Country: country.Name, + CountryISO: country.ISO, + CountryEU: country.IsEU, + City: city.Name, + Hostname: hostname, + Latitude: city.Latitude, + Longitude: city.Longitude, }, nil } diff --git a/http/http_test.go b/http/http_test.go index fcbbf79..8b6d341 100644 --- a/http/http_test.go +++ b/http/http_test.go @@ -17,11 +17,11 @@ func lookupPort(net.IP, uint64) error { return nil } type testDb struct{} func (t *testDb) Country(net.IP) (geo.Country, error) { - return geo.Country{Name: "Elbonia", ISO: "EB"}, nil + return geo.Country{Name: "Elbonia", ISO: "EB", IsEU: true}, nil } func (t *testDb) City(net.IP) (geo.City, error) { - return geo.City{Name: "Bornyasherk"}, nil + return geo.City{Name: "Bornyasherk", Latitude: 63.416667, Longitude: 10.416667}, nil } func (t *testDb) IsEmpty() bool { return false } @@ -128,7 +128,7 @@ func TestJSONHandlers(t *testing.T) { out string status int }{ - {s.URL, `{"ip":"127.0.0.1","ip_decimal":2130706433,"country":"Elbonia","country_iso":"EB","city":"Bornyasherk","hostname":"localhost"}`, 200}, + {s.URL, `{"ip":"127.0.0.1","ip_decimal":2130706433,"country":"Elbonia","country_eu":true,"country_iso":"EB","city":"Bornyasherk","hostname":"localhost","latitude":63.416667,"longitude":10.416667}`, 200}, {s.URL + "/port/foo", `{"error":"Invalid port: 0"}`, 400}, {s.URL + "/port/0", `{"error":"Invalid port: 0"}`, 400}, {s.URL + "/port/65356", `{"error":"Invalid port: 65356"}`, 400}, diff --git a/iputil/geo/geo.go b/iputil/geo/geo.go index f1be5cf..5509c2f 100644 --- a/iputil/geo/geo.go +++ b/iputil/geo/geo.go @@ -14,9 +14,9 @@ type Reader interface { } type Country struct { - Name string - ISO string - IsInEuropeanUnion bool + Name string + ISO string + IsEU bool } type City struct { @@ -70,9 +70,9 @@ func (g *geoip) Country(ip net.IP) (Country, error) { if record.RegisteredCountry.IsoCode != "" && country.ISO == "" { country.ISO = record.RegisteredCountry.IsoCode } - country.IsInEuropeanUnion = record.Country.IsInEuropeanUnion + country.IsEU = record.Country.IsInEuropeanUnion if record.RegisteredCountry.IsoCode != "" && country.ISO == "" { - country.IsInEuropeanUnion = record.RegisteredCountry.IsInEuropeanUnion + country.IsEU = record.RegisteredCountry.IsInEuropeanUnion } return country, nil }