forked from mirror/cast
feat: updating ToStringSliceE to support some other slices
This commit is contained in:
parent
1ffadf5510
commit
580a25aa7d
|
@ -1048,6 +1048,12 @@ func TestToStringSliceE(t *testing.T) {
|
||||||
expect []string
|
expect []string
|
||||||
iserr bool
|
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},
|
{[]string{"a", "b"}, []string{"a", "b"}, false},
|
||||||
{[]interface{}{1, 3}, []string{"1", "3"}, false},
|
{[]interface{}{1, 3}, []string{"1", "3"}, false},
|
||||||
{interface{}(1), []string{"1"}, false},
|
{interface{}(1), []string{"1"}, false},
|
||||||
|
|
30
caste.go
30
caste.go
|
@ -1129,6 +1129,36 @@ func ToStringSliceE(i interface{}) ([]string, error) {
|
||||||
return a, nil
|
return a, nil
|
||||||
case []string:
|
case []string:
|
||||||
return v, nil
|
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:
|
case string:
|
||||||
return strings.Fields(v), nil
|
return strings.Fields(v), nil
|
||||||
case interface{}:
|
case interface{}:
|
||||||
|
|
Loading…
Reference in New Issue