Implement ISO lookup and Map display

This commit is contained in:
Johann Richard 2018-02-04 17:33:00 +01:00
parent bd6946b470
commit c051321b11
4 changed files with 5 additions and 4 deletions

View File

@ -46,7 +46,7 @@ $ http --json ifconfig.co
{
"city": "Bornyasherk",
"country": "Elbonia",
"iso": "EB",
"isoCountry": "EB",
"ip": "127.0.0.1",
"ip_decimal": 2130706433
}

View File

@ -34,7 +34,7 @@ type Response struct {
IP net.IP `json:"ip"`
IPDecimal *big.Int `json:"ip_decimal"`
Country string `json:"country,omitempty"`
CountryISO string `json:"iso,omitempty"`
CountryISO string `json:"isoCountry,omitempty"`
City string `json:"city,omitempty"`
Hostname string `json:"hostname,omitempty"`
}

View File

@ -62,6 +62,7 @@ func TestCLIHandlers(t *testing.T) {
{s.URL, "127.0.0.1\n", 200, "foo/bar", textMediaType},
{s.URL + "/ip", "127.0.0.1\n", 200, "", ""},
{s.URL + "/country", "Elbonia\n", 200, "", ""},
{s.URL + "/iso", "EB\n", 200, "", ""},
{s.URL + "/city", "Bornyasherk\n", 200, "", ""},
{s.URL + "/foo", "404 page not found", 404, "", ""},
}
@ -89,7 +90,7 @@ func TestJSONHandlers(t *testing.T) {
out string
status int
}{
{s.URL, `{"ip":"127.0.0.1","ip_decimal":2130706433,"country":"Elbonia","iso":"EB","city":"Bornyasherk","hostname":"localhost"}`, 200},
{s.URL, `{"ip":"127.0.0.1","ip_decimal":2130706433,"country":"Elbonia","isoCountry":"EB","city":"Bornyasherk","hostname":"localhost"}`, 200},
{s.URL + "/port/foo", `{"error":"404 page not found"}`, 404},
{s.URL + "/port/0", `{"error":"Invalid port: 0"}`, 400},
{s.URL + "/port/65356", `{"error":"Invalid port: 65356"}`, 400},

View File

@ -82,7 +82,7 @@ $ http {{ .Host }}/json
{ {{ if .IsLookupCityEnabled }}
"city": "{{ .City }}",
"country": "{{ .Country }}",
"iso": "{{ .CountryISO }}",{{ end }}{{ if .IsLookupAddrEnabled }}
"isoCountry": "{{ .CountryISO }}",{{ end }}{{ if .IsLookupAddrEnabled }}
"hostname": "{{ .Hostname }}",{{ end }}
"ip": "{{ .IP }}",
"ip_decimal": {{ .IPDecimal }}