aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlphakilo <Alphakilo@users.noreply.github.com>2022-09-04 00:06:01 +0200
committerAlphakilo <Alphakilo@users.noreply.github.com>2022-09-04 00:06:01 +0200
commitdcefd6f1c644598ea11549140b17ddab4b589ff9 (patch)
tree4179b86152bfe743329887699108075ad82149bb
parentffa6674637a5bf906d78ae6675f9a4680a78ab7b (diff)
implement `/asn-org` endpoint
-rw-r--r--http/http.go10
-rw-r--r--http/http_test.go1
2 files changed, 11 insertions, 0 deletions
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 {