0x4a52466c696e74 1 year ago
parent
commit
b7b6278175
4 changed files with 8 additions and 5 deletions
  1. 1 0
      text/config/ini/test.ini
  2. 2 1
      text/config/ini/tmp.ini
  3. 3 0
      text/config/ini/z_test.go
  4. 2 4
      value/value.go

+ 1 - 0
text/config/ini/test.ini

@@ -1,6 +1,7 @@
 #[main]
 one = 1002
 db_connection = http://localhost
+arr = one, two, three
 
 [cool]
 # Comment

+ 2 - 1
text/config/ini/tmp.ini

@@ -1,6 +1,7 @@
 [main]
-db_connection = http://localhost
 one = 1002
+db_connection = http://localhost
+arr = one, two, three
 
 [cool]
 key = val

+ 3 - 0
text/config/ini/z_test.go

@@ -30,6 +30,9 @@ func TestINI(t *testing.T) {
 	main, check := conf.Section("main")
 	t.Log(main, check)
 
+	arr := main.ValueDefault("arr", []string{})
+	t.Log(arr)
+
 	cool, check := conf.Section("cool")
 	t.Log(cool, check)
 

+ 2 - 4
value/value.go

@@ -3,7 +3,6 @@ package value
 import (
 	"encoding/json"
 	"fmt"
-	"log"
 	"reflect"
 	"strconv"
 	"strings"
@@ -67,7 +66,7 @@ func (s *Value) Setup(val interface{}) (res bool) {
 				{
 					slType := rType.Elem()
 					if rr.Kind() == reflect.Slice {
-						slRes := reflect.MakeSlice(slType, rr.Len(), rr.Cap())
+						slRes := reflect.MakeSlice(rType, 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))
@@ -80,8 +79,7 @@ func (s *Value) Setup(val interface{}) (res bool) {
 					} 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))
+						slRes := reflect.MakeSlice(rType, len(sls), cap(sls))
 						for i, sVal := range sls {
 							sItem := reflect.ValueOf(strings.TrimSpace(sVal))
 							switch {