Browse Source

Merge 2e0cffc044 into 1ffadf5510

pull/85/merge
Paco Preciado Mendoza GitHub 4 years ago
parent
commit
a4885760a6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions
  1. +2
    -0
      cast_test.go
  2. +5
    -0
      caste.go

+ 2
- 0
cast_test.go View File

@@ -6,6 +6,7 @@
package cast

import (
"errors"
"fmt"
"html/template"
"testing"
@@ -1051,6 +1052,7 @@ func TestToStringSliceE(t *testing.T) {
{[]string{"a", "b"}, []string{"a", "b"}, false},
{[]interface{}{1, 3}, []string{"1", "3"}, false},
{interface{}(1), []string{"1"}, false},
{[]error{errors.New("a"), errors.New("b")}, []string{"a", "b"}, false},
// errors
{nil, nil, true},
{testing.T{}, nil, true},


+ 5
- 0
caste.go View File

@@ -1131,6 +1131,11 @@ func ToStringSliceE(i interface{}) ([]string, error) {
return v, nil
case string:
return strings.Fields(v), nil
case []error:
for _, err := range i.([]error) {
a = append(a, err.Error())
}
return a, nil
case interface{}:
str, err := ToStringE(v)
if err != nil {


Loading…
Cancel
Save