diff --git a/stringutil/stringutil.go b/stringutil/stringutil.go deleted file mode 100644 index aedb198..0000000 --- a/stringutil/stringutil.go +++ /dev/null @@ -1,21 +0,0 @@ -package stringutil - -// Map applies f to each string in in. -func Map(in []string, f func(string) string) []string { - res := make([]string, 0, len(in)) - for _, s := range in { - res = append(res, f(s)) - } - return res -} - -// Contains returns true if in contains element, -// false if not. -func Contains(in []string, element string) bool { - for _, a := range in { - if a == element { - return true - } - } - return false -} diff --git a/stringutil/stringutil_test.go b/stringutil/stringutil_test.go deleted file mode 100644 index 61ab494..0000000 --- a/stringutil/stringutil_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package stringutil_test - -import ( - "github.com/lithictech/go-aperitif/stringutil" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "strings" - "testing" -) - -func TestStringUtil(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "stringutil Suite") -} - -var _ = Describe("Map", func() { - It("maps the input slice", func() { - s := []string{"a", "b"} - res := stringutil.Map(s, strings.ToUpper) - Expect(res).To(Equal([]string{"A", "B"})) - }) -}) - -var _ = Describe("Contains", func() { - It("is true if the slice contains the string", func() { - s := []string{"a", "b"} - Expect(stringutil.Contains(s, "a")).To(BeTrue()) - Expect(stringutil.Contains(s, "A")).To(BeFalse()) - }) -}) diff --git a/validator/stringutil.go b/validator/stringutil.go new file mode 100644 index 0000000..8ea7f8f --- /dev/null +++ b/validator/stringutil.go @@ -0,0 +1,18 @@ +package validator + +func mapString(in []string, f func(string) string) []string { + res := make([]string, 0, len(in)) + for _, s := range in { + res = append(res, f(s)) + } + return res +} + +func containsString(in []string, element string) bool { + for _, a := range in { + if a == element { + return true + } + } + return false +} diff --git a/validator/validators.go b/validator/validators.go index 223ac2b..357a36b 100644 --- a/validator/validators.go +++ b/validator/validators.go @@ -3,7 +3,6 @@ package validator import ( "errors" "github.com/lithictech/go-aperitif/kronos" - "github.com/lithictech/go-aperitif/stringutil" "github.com/rgalanakis/validator" "net/url" "regexp" @@ -92,7 +91,7 @@ func validateEnumImpl(v interface{}, param string, mapper func(string) string) e return err } if mapper != nil { - choices = stringutil.Map(choices, mapper) + choices = mapString(choices, mapper) } if s, ok := v.(string); ok { @@ -110,7 +109,7 @@ func validateEnumImpl(v interface{}, param string, mapper func(string) string) e return validator.ErrBadParameter } if mapper != nil { - ss = stringutil.Map(ss, mapper) + ss = mapString(ss, mapper) } return validateEnumImplSlice(ss, choices) } @@ -139,7 +138,7 @@ func validateEnumImplStr(s string, choices []string, optional bool) error { func validateEnumImplSlice(ss []string, choices []string) error { for _, s := range ss { - if !stringutil.Contains(choices, s) { + if !containsString(choices, s) { return newError("element not one of " + strings.Join(choices, "|")) } }