From 7d5d21de5278e800647d9cbc3f7f2694b158da3d Mon Sep 17 00:00:00 2001 From: Fossil Date: Sun, 21 May 2023 19:14:16 +0200 Subject: [PATCH 1/5] Use available width when sponsor is disabled This makes sure a v6 address doesn't line break on desktop. --- html/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/html/index.html b/html/index.html index 9557084..2ca69e6 100644 --- a/html/index.html +++ b/html/index.html @@ -32,7 +32,7 @@
-
+

{{ .Host }} — What is my IP address?

{{ .IP }}

@@ -42,8 +42,8 @@

+ {{ if .Sponsor }}
- {{ if .Sponsor }}
@@ -63,8 +63,8 @@
- {{ end }}
+ {{ end }}
From 3f69eab6e55f665d3441be9bbe5f7d9bbc781aa6 Mon Sep 17 00:00:00 2001 From: Alphakilo Date: Sun, 4 Sep 2022 00:08:14 +0200 Subject: [PATCH 2/5] 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: From 667792aef3d033050a726830a48e4b5000f51bff Mon Sep 17 00:00:00 2001 From: Alphakilo Date: Sun, 4 Sep 2022 00:06:01 +0200 Subject: [PATCH 3/5] 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 16a75635e8ea73722a764e7e2d838540e6d4638d Mon Sep 17 00:00:00 2001 From: Marcell Martini Date: Sun, 27 Dec 2020 18:19:33 -0400 Subject: [PATCH 4/5] feat: Remove if inside loop from String() --- cmd/echoip/main.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cmd/echoip/main.go b/cmd/echoip/main.go index 737a4f4..f3d4c94 100644 --- a/cmd/echoip/main.go +++ b/cmd/echoip/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "log" + "strings" "os" @@ -14,14 +15,7 @@ import ( type multiValueFlag []string func (f *multiValueFlag) String() string { - vs := "" - for i, v := range *f { - vs += v - if i < len(*f)-1 { - vs += ", " - } - } - return vs + return strings.Join([]string(*f), ", ") } func (f *multiValueFlag) Set(v string) error { From 0eb7bf455d61ebdf2383756d4468889a23973f22 Mon Sep 17 00:00:00 2001 From: Marcell Martini Date: Sun, 27 Dec 2020 18:21:02 -0400 Subject: [PATCH 5/5] feat: Adding test to main.go --- cmd/echoip/main_test.go | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 cmd/echoip/main_test.go diff --git a/cmd/echoip/main_test.go b/cmd/echoip/main_test.go new file mode 100644 index 0000000..045a82a --- /dev/null +++ b/cmd/echoip/main_test.go @@ -0,0 +1,42 @@ +package main + +import "testing" + +func TestMultiValueFlagString(t *testing.T) { + var xmvf = []struct { + values multiValueFlag + expect string + }{ + { + values: multiValueFlag{ + "test", + "with multiples", + "flags", + }, + expect: `test, with multiples, flags`, + }, + { + values: multiValueFlag{ + "test", + }, + expect: `test`, + }, + { + values: multiValueFlag{ + "", + }, + expect: ``, + }, + { + values: nil, + expect: ``, + }, + } + + for _, mvf := range xmvf { + got := mvf.values.String() + if got != mvf.expect { + t.Errorf("\nFor: %#v\nExpected: %v\nGot: %v", mvf.values, mvf.expect, got) + } + } +}