Skip to content

Commit d84665c

Browse files
authored
Merge pull request #162 from Alphakilo/master
Implement `/asn-org` endpoint
2 parents 31b161f + 44ce088 commit d84665c

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Bornyasherk
4040
4141
$ curl ifconfig.co/asn
4242
AS59795
43+
44+
$ curl ifconfig.co/asn-org
45+
Hosting4Real
4346
```
4447

4548
As JSON:

http/http.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ func (s *Server) CLIASNHandler(w http.ResponseWriter, r *http.Request) *appError
240240
return nil
241241
}
242242

243+
func (s *Server) CLIASNOrgHandler(w http.ResponseWriter, r *http.Request) *appError {
244+
response, err := s.newResponse(r)
245+
if err != nil {
246+
return badRequest(err).WithMessage(err.Error()).AsJSON()
247+
}
248+
fmt.Fprintf(w, "%s\n", response.ASNOrg)
249+
return nil
250+
}
251+
243252
func (s *Server) JSONHandler(w http.ResponseWriter, r *http.Request) *appError {
244253
response, err := s.newResponse(r)
245254
if err != nil {
@@ -431,6 +440,7 @@ func (s *Server) Handler() http.Handler {
431440
r.Route("GET", "/city", s.CLICityHandler)
432441
r.Route("GET", "/coordinates", s.CLICoordinatesHandler)
433442
r.Route("GET", "/asn", s.CLIASNHandler)
443+
r.Route("GET", "/asn-org", s.CLIASNOrgHandler)
434444
}
435445

436446
// Browser

http/http_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func TestCLIHandlers(t *testing.T) {
9494
{s.URL + "/city", "Bornyasherk\n", 200, "", ""},
9595
{s.URL + "/foo", "404 page not found", 404, "", ""},
9696
{s.URL + "/asn", "AS59795\n", 200, "", ""},
97+
{s.URL + "/asn-org", "Hosting4Real\n", 200, "", ""},
9798
}
9899

99100
for _, tt := range tests {

0 commit comments

Comments
 (0)