Kaynağa Gözat

Merge 9b1b06389b into 1ffadf5510

pull/60/merge
Jun Zhang GitHub 4 yıl önce
ebeveyn
işleme
fdd5c7dd0b
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: 4AEE18F83AFDEB23
2 değiştirilmiş dosya ile 12 ekleme ve 1 silme
  1. +4
    -0
      cast_test.go
  2. +8
    -1
      caste.go

+ 4
- 0
cast_test.go Dosyayı Görüntüle

@@ -1051,6 +1051,10 @@ func TestToStringSliceE(t *testing.T) {
{[]string{"a", "b"}, []string{"a", "b"}, false},
{[]interface{}{1, 3}, []string{"1", "3"}, false},
{interface{}(1), []string{"1"}, false},
{"a", []string{"a"}, false},
{"a b", []string{"a", "b"}, false},
{"a,b", []string{"a", "b"}, false},
{"a b,c", []string{"a", "b,c"}, false},
// errors
{nil, nil, true},
{testing.T{}, nil, true},


+ 8
- 1
caste.go Dosyayı Görüntüle

@@ -1130,7 +1130,14 @@ func ToStringSliceE(i interface{}) ([]string, error) {
case []string:
return v, nil
case string:
return strings.Fields(v), nil
slice := strings.Fields(v)
// if the string can be splited by white space
// return slice immediately
if len(slice) > 1 {
return slice, nil
}
// otherwise, try to split string by comma
return strings.Split(v, ","), nil
case interface{}:
str, err := ToStringE(v)
if err != nil {


Yükleniyor…
İptal
Kaydet