Skip to content

Commit

Permalink
Merge pull request #162 from Alphakilo/master
Browse files Browse the repository at this point in the history
Implement `/asn-org` endpoint
  • Loading branch information
mpolden authored May 21, 2023
2 parents 31b161f + 44ce088 commit d84665c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Bornyasherk
$ curl ifconfig.co/asn
AS59795
$ curl ifconfig.co/asn-org
Hosting4Real
```

As JSON:
Expand Down
10 changes: 10 additions & 0 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d84665c

Please sign in to comment.