Skip to content

Commit

Permalink
Remove stringutil
Browse files Browse the repository at this point in the history
Go has generics now, so such utilities are not generally useful.
Libraries should have generic utilities instead.
  • Loading branch information
rgalanakis committed Jul 31, 2024
1 parent 490ca58 commit 572476a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 55 deletions.
21 changes: 0 additions & 21 deletions stringutil/stringutil.go

This file was deleted.

30 changes: 0 additions & 30 deletions stringutil/stringutil_test.go

This file was deleted.

18 changes: 18 additions & 0 deletions validator/stringutil.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 3 additions & 4 deletions validator/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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, "|"))
}
}
Expand Down

0 comments on commit 572476a

Please sign in to comment.