From e5798c74d2d473ff8965556ab74c612619de3dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tisa=CC=88ter?= Date: Thu, 17 Jul 2014 08:37:25 +0200 Subject: [PATCH] Add helper for lowercase list of strings --- consul/util.go | 9 +++++++++ consul/util_test.go | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/consul/util.go b/consul/util.go index 00815ea10c..96ee5c3276 100644 --- a/consul/util.go +++ b/consul/util.go @@ -9,6 +9,7 @@ import ( "path/filepath" "runtime" "strconv" + "strings" "github.com/hashicorp/serf/serf" ) @@ -68,6 +69,14 @@ func strContains(l []string, s string) bool { return false } +func ToLowerList(l []string) []string { + var out []string + for _, value := range l { + out = append(out, strings.ToLower(value)) + } + return out +} + // ensurePath is used to make sure a path exists func ensurePath(path string, dir bool) error { if !dir { diff --git a/consul/util_test.go b/consul/util_test.go index 107146b521..91b7fd2f53 100644 --- a/consul/util_test.go +++ b/consul/util_test.go @@ -18,6 +18,15 @@ func TestStrContains(t *testing.T) { } } +func TestToLowerList(t *testing.T) { + l := []string{"ABC", "Abc", "abc"} + for _, value := range ToLowerList(l) { + if value != "abc" { + t.Fatalf("failed lowercasing") + } + } +} + func TestIsPrivateIP(t *testing.T) { if !isPrivateIP("192.168.1.1") { t.Fatalf("bad")