aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-05-21 20:26:14 +0200
committerGitHub <noreply@github.com>2023-05-21 20:26:14 +0200
commitd84665c26cf7df612061e9c35abe325ba9d86b8d (patch)
treed0292f63eb8dccd38680bf7da41b60e8e967963c
parent31b161feeea2e8ee096811db2bf115ea52c92cbc (diff)
parent44ce088bb3d96cff5cf4a663cc6d7b6892169002 (diff)
Merge pull request #162 from Alphakilo/masterHEADmaster
Implement `/asn-org` endpoint
-rw-r--r--README.md3
-rw-r--r--http/http.go10
-rw-r--r--http/http_test.go1
3 files changed, 14 insertions, 0 deletions
diff --git a/README.md b/README.md
index 1c801e9..5f181a8 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,9 @@ Bornyasherk
$ curl ifconfig.co/asn
AS59795
+
+$ curl ifconfig.co/asn-org
+Hosting4Real
```
As JSON:
diff --git a/http/http.go b/http/http.go
index 626d75b..d0a1838 100644
--- a/http/http.go
+++ b/http/http.go
@@ -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
diff --git a/http/http_test.go b/http/http_test.go
index 29dcf1b..69c9e37 100644
--- a/http/http_test.go
+++ b/http/http_test.go
@@ -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 {