Merge pull request #162 from Alphakilo/master

Implement `/asn-org` endpoint
This commit is contained in:
Martin Polden 2023-05-21 20:26:14 +02:00 committed by GitHub
commit d84665c26c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -40,6 +40,9 @@ Bornyasherk
$ curl ifconfig.co/asn
AS59795
$ curl ifconfig.co/asn-org
Hosting4Real
```
As JSON:

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 {