|
@@ -65,7 +65,6 @@ func (s *Value) Setup(val interface{}) (res bool) {
|
|
|
}
|
|
|
case reflect.Slice:
|
|
|
{
|
|
|
- log.Println("Slice")
|
|
|
slType := rType.Elem()
|
|
|
if rr.Kind() == reflect.Slice {
|
|
|
slRes := reflect.MakeSlice(slType, rr.Len(), rr.Cap())
|
|
@@ -79,8 +78,73 @@ func (s *Value) Setup(val interface{}) (res bool) {
|
|
|
rr.Elem().Set(slRes)
|
|
|
res = true
|
|
|
} else if rl.Kind() == reflect.String {
|
|
|
-
|
|
|
+ slType := rType.Elem()
|
|
|
+ sls := strings.Split(rl.String(), ",")
|
|
|
+ log.Println(slType, rr.Type())
|
|
|
+ slRes := reflect.MakeSlice(rr.Type().Elem(), len(sls), cap(sls))
|
|
|
+ for i, sVal := range sls {
|
|
|
+ sItem := reflect.ValueOf(strings.TrimSpace(sVal))
|
|
|
+ switch {
|
|
|
+ case isKindNumber(slType.Kind()):
|
|
|
+ {
|
|
|
+ numVal, err := strconv.ParseFloat(sItem.String(), 64)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ sItem = reflect.ValueOf(numVal)
|
|
|
+ slRes.Index(i).Set(sItem.Convert(slType))
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ if !sItem.CanConvert(slType) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ slRes.Index(i).Set(sItem.Convert(slType))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rr.Elem().Set(slRes)
|
|
|
+ res = true
|
|
|
}
|
|
|
+ /*
|
|
|
+ log.Println("Slice")
|
|
|
+ slType := rType.Elem()
|
|
|
+ if rr.Kind() == reflect.Slice {
|
|
|
+ slRes := reflect.MakeSlice(slType, rr.Len(), rr.Cap())
|
|
|
+ for i := 0; i < rl.Len(); i++ {
|
|
|
+ if val := rl.Index(i); val.CanConvert(slType) {
|
|
|
+ slRes.Index(i).Set(val.Convert(slType))
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rr.Elem().Set(slRes)
|
|
|
+ res = true
|
|
|
+ } else if rl.Kind() == reflect.String {
|
|
|
+ log.Println("sl <===> str")
|
|
|
+ sls := strings.Split(rl.String(), ",")
|
|
|
+ log.Println(slType, rr.Type())
|
|
|
+ slRes := reflect.MakeSlice(slType, len(sls), cap(sls))
|
|
|
+ switch {
|
|
|
+ case isKindNumber(slType.Kind()):
|
|
|
+ log.Println("AAAAAAAAAAAAAAAAA")
|
|
|
+ for i, sVal := range sls {
|
|
|
+ numVal, err := strconv.ParseFloat(sVal, 64)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ rl := reflect.ValueOf(numVal)
|
|
|
+ if val := rl.Index(i); val.CanConvert(slType) {
|
|
|
+ slRes.Index(i).Set(val.Convert(slType))
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rr.Elem().Set(slRes)
|
|
|
+ res = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
}
|
|
|
default:
|
|
|
// json
|