implement `/asn-org` endpoint

This commit is contained in:
Alphakilo 2022-09-04 00:06:01 +02:00
parent ffa6674637
commit dcefd6f1c6
2 changed files with 11 additions and 0 deletions

View File

@ -240,6 +240,15 @@ func (s *Server) CLIASNHandler(w http.ResponseWriter, r *http.Request) *appError
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 {
response, err := s.newResponse(r)
if err != nil {
@ -431,6 +440,7 @@ func (s *Server) Handler() http.Handler {
r.Route("GET", "/city", s.CLICityHandler)
r.Route("GET", "/coordinates", s.CLICoordinatesHandler)
r.Route("GET", "/asn", s.CLIASNHandler)
r.Route("GET", "/asn-org", s.CLIASNOrgHandler)
}
// Browser

View File

@ -94,6 +94,7 @@ func TestCLIHandlers(t *testing.T) {
{s.URL + "/city", "Bornyasherk\n", 200, "", ""},
{s.URL + "/foo", "404 page not found", 404, "", ""},
{s.URL + "/asn", "AS59795\n", 200, "", ""},
{s.URL + "/asn-org", "Hosting4Real\n", 200, "", ""},
}
for _, tt := range tests {