diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2019-10-15 00:04:45 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2019-10-15 00:04:45 -0400 |
| commit | 882696f858a764ea9354763370e10aa15d31d1b4 (patch) | |
| tree | 8ec5ffd08a100d617939f576d532d59803e73248 /conv | |
| parent | 4e8d13bc227b8ffdc4ce5232555cb683212b0c30 (diff) | |
Slight performance improvement & refactoring
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'conv')
| -rw-r--r-- | conv/conv.go | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/conv/conv.go b/conv/conv.go index cd9cb771..20435f93 100644 --- a/conv/conv.go +++ b/conv/conv.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + iconv "github.com/hairyhenderson/gomplate/internal/conv" "github.com/pkg/errors" ) @@ -82,7 +83,7 @@ func Join(in interface{}, sep string) (out string, err error) { var a []interface{} a, ok = in.([]interface{}) if !ok { - a, err = interfaceSlice(in) + a, err = iconv.InterfaceSlice(in) if err != nil { return "", errors.Wrap(err, "Input to Join must be an array") } @@ -99,21 +100,6 @@ func Join(in interface{}, sep string) (out string, err error) { return "", errors.New("Input to Join must be an array") } -func interfaceSlice(slice interface{}) ([]interface{}, error) { - s := reflect.ValueOf(slice) - kind := s.Kind() - switch kind { - case reflect.Slice, reflect.Array: - ret := make([]interface{}, s.Len()) - for i := 0; i < s.Len(); i++ { - ret[i] = s.Index(i).Interface() - } - return ret, nil - default: - return nil, errors.Errorf("expected an array or slice, but got a %T", s) - } -} - // Has determines whether or not a given object has a property with the given key func Has(in interface{}, key interface{}) bool { av := reflect.ValueOf(in) |
