0x4a52466c696e74 hace 2 años
padre
commit
3624d0d321
Se han modificado 2 ficheros con 24 adiciones y 0 borrados
  1. 20 0
      value/value.go
  2. 4 0
      value/z_test.go

+ 20 - 0
value/value.go

@@ -3,6 +3,7 @@ package value
 import (
 	"encoding/json"
 	"fmt"
+	"log"
 	"reflect"
 	"strconv"
 	"strings"
@@ -62,6 +63,25 @@ func (s *Value) Setup(val interface{}) (res bool) {
 						res = true
 					}
 				}
+			case reflect.Slice:
+				{
+					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 {
+
+					}
+				}
 			default:
 				// json
 				i := reflect.New(rr.Elem().Type()).Interface()

+ 4 - 0
value/z_test.go

@@ -12,4 +12,8 @@ func TestValue(t *testing.T) {
 
 	val = ValueOf(100.55)
 	log.Println(val.Int())
+
+	val = ValueOf("one, two, three")
+	var sls []string
+	t.Log(val.Setup(&sls))
 }