Rename fields

This commit is contained in:
Martin Polden 2018-08-27 21:44:00 +02:00
parent de54d88327
commit 3e1d4425cd
3 changed files with 26 additions and 26 deletions

View File

@ -31,15 +31,15 @@ type Server struct {
} }
type Response struct { type Response struct {
IP net.IP `json:"ip"` IP net.IP `json:"ip"`
IPDecimal *big.Int `json:"ip_decimal"` IPDecimal *big.Int `json:"ip_decimal"`
Country string `json:"country,omitempty"` Country string `json:"country,omitempty"`
CountryISO string `json:"country_iso,omitempty"` CountryEU bool `json:"country_eu,omitempty"`
City string `json:"city,omitempty"` CountryISO string `json:"country_iso,omitempty"`
Hostname string `json:"hostname,omitempty"` City string `json:"city,omitempty"`
IsInEuropeanUnion bool `json:"is_in_european_union,omitempty"` Hostname string `json:"hostname,omitempty"`
Latitude float64 `json:"location_latitude,omitempty"` Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"location_longitude,omitempty"` Longitude float64 `json:"longitude,omitempty"`
} }
type PortResponse struct { type PortResponse struct {
@ -98,15 +98,15 @@ func (s *Server) newResponse(r *http.Request) (Response, error) {
hostname, _ = s.LookupAddr(ip) hostname, _ = s.LookupAddr(ip)
} }
return Response{ return Response{
IP: ip, IP: ip,
IPDecimal: ipDecimal, IPDecimal: ipDecimal,
Country: country.Name, Country: country.Name,
CountryISO: country.ISO, CountryISO: country.ISO,
IsInEuropeanUnion: country.IsInEuropeanUnion, CountryEU: country.IsEU,
City: city.Name, City: city.Name,
Hostname: hostname, Hostname: hostname,
Latitude: city.Latitude, Latitude: city.Latitude,
Longitude: city.Longitude, Longitude: city.Longitude,
}, nil }, nil
} }

View File

@ -17,11 +17,11 @@ func lookupPort(net.IP, uint64) error { return nil }
type testDb struct{} type testDb struct{}
func (t *testDb) Country(net.IP) (geo.Country, error) { 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) { 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 } func (t *testDb) IsEmpty() bool { return false }
@ -128,7 +128,7 @@ func TestJSONHandlers(t *testing.T) {
out string out string
status int 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/foo", `{"error":"Invalid port: 0"}`, 400},
{s.URL + "/port/0", `{"error":"Invalid port: 0"}`, 400}, {s.URL + "/port/0", `{"error":"Invalid port: 0"}`, 400},
{s.URL + "/port/65356", `{"error":"Invalid port: 65356"}`, 400}, {s.URL + "/port/65356", `{"error":"Invalid port: 65356"}`, 400},

View File

@ -14,9 +14,9 @@ type Reader interface {
} }
type Country struct { type Country struct {
Name string Name string
ISO string ISO string
IsInEuropeanUnion bool IsEU bool
} }
type City struct { type City struct {
@ -70,9 +70,9 @@ func (g *geoip) Country(ip net.IP) (Country, error) {
if record.RegisteredCountry.IsoCode != "" && country.ISO == "" { if record.RegisteredCountry.IsoCode != "" && country.ISO == "" {
country.ISO = record.RegisteredCountry.IsoCode country.ISO = record.RegisteredCountry.IsoCode
} }
country.IsInEuropeanUnion = record.Country.IsInEuropeanUnion country.IsEU = record.Country.IsInEuropeanUnion
if record.RegisteredCountry.IsoCode != "" && country.ISO == "" { if record.RegisteredCountry.IsoCode != "" && country.ISO == "" {
country.IsInEuropeanUnion = record.RegisteredCountry.IsInEuropeanUnion country.IsEU = record.RegisteredCountry.IsInEuropeanUnion
} }
return country, nil return country, nil
} }