From 8d17101741c81653ee960aa20f9febb31f1218aa Mon Sep 17 00:00:00 2001 From: Paco Preciado Mendoza <__pm@outlook.com> Date: Thu, 23 Jul 2020 16:45:38 -0500 Subject: [PATCH] Convert error slice to string slice * feat: added test case for error slice to parse to string * feat: added handler to convert an error slice to string slice --- cast_test.go | 2 ++ caste.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/cast_test.go b/cast_test.go index 9fd0437..cc4ebce 100644 --- a/cast_test.go +++ b/cast_test.go @@ -6,6 +6,7 @@ package cast import ( + "errors" "fmt" "html/template" "testing" @@ -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}, diff --git a/caste.go b/caste.go index a280b92..9ac1015 100644 --- a/caste.go +++ b/caste.go @@ -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 {