mirror of
https://github.com/mpolden/echoip.git
synced 2024-11-13 00:42:46 +01:00
implement /asn-org
endpoint
This commit is contained in:
parent
ffa6674637
commit
dcefd6f1c6
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
Block a user