Skip to content

Commit

Permalink
Convert error slice to string slice
Browse files Browse the repository at this point in the history
* feat: added test case for error slice to parse to string

* feat: added handler to convert an error slice to string slice
  • Loading branch information
PacoDw committed Jul 23, 2020
1 parent 580a25a commit 8d17101
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package cast

import (
"errors"
"fmt"
"html/template"
"testing"
Expand Down Expand Up @@ -1057,6 +1058,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},
Expand Down
5 changes: 5 additions & 0 deletions caste.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,11 @@ func ToStringSliceE(i interface{}) ([]string, error) {
return a, 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 {
Expand Down

0 comments on commit 8d17101

Please sign in to comment.