diff options
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | cmd/echoip/main.go | 10 | ||||
-rw-r--r-- | cmd/echoip/main_test.go | 42 |
3 files changed, 49 insertions, 8 deletions
@@ -110,6 +110,11 @@ Hub](https://hub.docker.com/r/mpolden/echoip), which can be downloaded with: `docker pull mpolden/echoip` +## [GeoIP](https://www.maxmind.com/en/geoip2-databases)/[GeoLite](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?) Database (MaxMind) +To utilise MaxMind [GeoIP](https://www.maxmind.com/en/geoip2-databases)/[GeoLite](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?) database to enhance the information provided to end users, you can download the relevant **binary** databases (`.mmdb` format) directly from MaxMind using the above links. + +**Please Note**: This has only been tested using the free, GeoLite database. + ### Usage ``` 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 { 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) + } + } +} |