From dcefd6f1c644598ea11549140b17ddab4b589ff9 Mon Sep 17 00:00:00 2001 From: Alphakilo Date: Sun, 4 Sep 2022 00:06:01 +0200 Subject: [PATCH 1/2] implement `/asn-org` endpoint --- http/http.go | 10 ++++++++++ http/http_test.go | 1 + 2 files changed, 11 insertions(+) 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 { From 44ce088bb3d96cff5cf4a663cc6d7b6892169002 Mon Sep 17 00:00:00 2001 From: Alphakilo Date: Sun, 4 Sep 2022 00:08:14 +0200 Subject: [PATCH 2/2] update docs --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 444eb53..930072b 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: