mirror of https://github.com/mpolden/echoip
Merge pull request #162 from Alphakilo/master
Implement `/asn-org` endpoint
This commit is contained in:
commit
d84665c26c
|
@ -40,6 +40,9 @@ Bornyasherk
|
||||||
|
|
||||||
$ curl ifconfig.co/asn
|
$ curl ifconfig.co/asn
|
||||||
AS59795
|
AS59795
|
||||||
|
|
||||||
|
$ curl ifconfig.co/asn-org
|
||||||
|
Hosting4Real
|
||||||
```
|
```
|
||||||
|
|
||||||
As JSON:
|
As JSON:
|
||||||
|
|
10
http/http.go
10
http/http.go
|
@ -240,6 +240,15 @@ func (s *Server) CLIASNHandler(w http.ResponseWriter, r *http.Request) *appError
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) CLIASNOrgHandler(w http.ResponseWriter, r *http.Request) *appError {
|
||||||
|
response, err := s.newResponse(r)
|
||||||
|
if err != nil {
|
||||||
|
return badRequest(err).WithMessage(err.Error()).AsJSON()
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s\n", response.ASNOrg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) JSONHandler(w http.ResponseWriter, r *http.Request) *appError {
|
func (s *Server) JSONHandler(w http.ResponseWriter, r *http.Request) *appError {
|
||||||
response, err := s.newResponse(r)
|
response, err := s.newResponse(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -431,6 +440,7 @@ func (s *Server) Handler() http.Handler {
|
||||||
r.Route("GET", "/city", s.CLICityHandler)
|
r.Route("GET", "/city", s.CLICityHandler)
|
||||||
r.Route("GET", "/coordinates", s.CLICoordinatesHandler)
|
r.Route("GET", "/coordinates", s.CLICoordinatesHandler)
|
||||||
r.Route("GET", "/asn", s.CLIASNHandler)
|
r.Route("GET", "/asn", s.CLIASNHandler)
|
||||||
|
r.Route("GET", "/asn-org", s.CLIASNOrgHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Browser
|
// Browser
|
||||||
|
|
|
@ -94,6 +94,7 @@ func TestCLIHandlers(t *testing.T) {
|
||||||
{s.URL + "/city", "Bornyasherk\n", 200, "", ""},
|
{s.URL + "/city", "Bornyasherk\n", 200, "", ""},
|
||||||
{s.URL + "/foo", "404 page not found", 404, "", ""},
|
{s.URL + "/foo", "404 page not found", 404, "", ""},
|
||||||
{s.URL + "/asn", "AS59795\n", 200, "", ""},
|
{s.URL + "/asn", "AS59795\n", 200, "", ""},
|
||||||
|
{s.URL + "/asn-org", "Hosting4Real\n", 200, "", ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
Loading…
Reference in New Issue