feat: updating ToStringSliceE to support some other slices

This commit is contained in:
zheng 2019-04-04 22:45:22 +08:00 committed by Bjørn Erik Pedersen
parent 1ffadf5510
commit 580a25aa7d
2 changed files with 36 additions and 0 deletions

View File

@ -1048,6 +1048,12 @@ func TestToStringSliceE(t *testing.T) {
expect []string
iserr bool
}{
{[]int{1, 2}, []string{"1", "2"}, false},
{[]int8{int8(1), int8(2)}, []string{"1", "2"}, false},
{[]int32{int32(1), int32(2)}, []string{"1", "2"}, false},
{[]int64{int64(1), int64(2)}, []string{"1", "2"}, false},
{[]float32{float32(1.01), float32(2.01)}, []string{"1.01", "2.01"}, false},
{[]float64{float64(1.01), float64(2.01)}, []string{"1.01", "2.01"}, false},
{[]string{"a", "b"}, []string{"a", "b"}, false},
{[]interface{}{1, 3}, []string{"1", "3"}, false},
{interface{}(1), []string{"1"}, false},

View File

@ -1129,6 +1129,36 @@ func ToStringSliceE(i interface{}) ([]string, error) {
return a, nil
case []string:
return v, nil
case []int8:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []int:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []int32:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []int64:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []float32:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []float64:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case string:
return strings.Fields(v), nil
case interface{}: