diff options
author | Martin Polden <mpolden@mpolden.no> | 2018-08-27 22:44:00 +0300 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2018-08-27 22:49:37 +0300 |
commit | 3e1d4425cdbb45ca53122f052e5d01b176b04150 (patch) | |
tree | 6e7363cfedeb283f820502de2aaed7848a49beaa /http | |
parent | de54d8832700a6915283604453fe85f29d0d6d2c (diff) |
Rename fields
Diffstat (limited to 'http')
-rw-r--r-- | http/http.go | 36 | ||||
-rw-r--r-- | http/http_test.go | 6 |
2 files changed, 21 insertions, 21 deletions
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}, |