@@ -10,12 +10,12 @@ type tagInfo struct {
1010 omit bool //表示这个字段忽略
1111}
1212
13- func (t * fieldNodeTree ) parseAny (key , scene string , el interface {}, isSelect bool ) {
14- typeOf := reflect .TypeOf (el )
15- valueOf := reflect .ValueOf (el )
13+ func (t * fieldNodeTree ) parseAny (key , scene string , valueOf reflect.Value , isSelect bool ) {
14+ typeOf := valueOf .Type ()
1615TakePointerValue: //取指针的值
1716 switch typeOf .Kind () {
18- case reflect .Ptr : //如果是指针类型则取地址重新判断类型
17+ case reflect .Ptr : //如果是指针类型则取值重新判断类型
18+ valueOf = valueOf .Elem ()
1919 typeOf = typeOf .Elem ()
2020 goto TakePointerValue
2121 case reflect .Struct :
@@ -110,12 +110,6 @@ func getSelectTag(scene string, pkgInfo string, i int, typeOf reflect.Type) tagI
110110}
111111
112112func parserMap (valueOf reflect.Value , t * fieldNodeTree , scene string , isSelect bool ) {
113-
114- takeVMap:
115- if valueOf .Kind () == reflect .Ptr {
116- valueOf = valueOf .Elem ()
117- goto takeVMap
118- }
119113 keys := valueOf .MapKeys ()
120114 if len (keys ) == 0 { //空map情况下解析为{}
121115 t .Val = struct {}{}
@@ -143,7 +137,7 @@ takeVMap:
143137 nodeTree .IsNil = true
144138 t .AddChild (nodeTree )
145139 } else {
146- nodeTree .parseAny (k , scene , val . Interface () , isSelect )
140+ nodeTree .parseAny (k , scene , val , isSelect )
147141 t .AddChild (nodeTree )
148142 }
149143 }
@@ -165,18 +159,6 @@ func parserBaseType(valueOf reflect.Value, t *fieldNodeTree, key string) {
165159}
166160
167161func parserStruct (typeOf reflect.Type , valueOf reflect.Value , t * fieldNodeTree , scene string , key string , isSelect bool ) {
168-
169- TakeValueOfPointerValue: //这里主要是考虑到有可能用的不是一级指针,如果是***int 等多级指针就需要不断的取值
170- if valueOf .Kind () == reflect .Ptr {
171- if valueOf .IsNil () {
172- t .IsNil = true
173- return
174- } else {
175- valueOf = valueOf .Elem ()
176- goto TakeValueOfPointerValue
177- }
178- }
179-
180162 if valueOf .CanConvert (timeTypes ) { //是time.Time类型或者底层是time.Time类型
181163 t .Key = key
182164 t .Val = valueOf .Interface ()
@@ -248,7 +230,7 @@ TakeValueOfPointerValue: //这里主要是考虑到有可能用的不是一级
248230 }
249231 }
250232
251- tree .parseAny (tag .UseFieldName , scene , value . Interface () , isSelect )
233+ tree .parseAny (tag .UseFieldName , scene , value , isSelect )
252234
253235 if t .IsAnonymous {
254236 t .AnonymousAddChild (tree )
@@ -263,7 +245,6 @@ TakeValueOfPointerValue: //这里主要是考虑到有可能用的不是一级
263245}
264246
265247func parserSliceOrArray (typeOf reflect.Type , valueOf reflect.Value , t * fieldNodeTree , scene string , key string , isSelect bool ) {
266-
267248 val1 := valueOf .Interface ()
268249 ok := valueOf .CanConvert (byteTypes )
269250 if ok {
@@ -310,7 +291,7 @@ func parserSliceOrArray(typeOf reflect.Type, valueOf reflect.Value, t *fieldNode
310291 node .IsNil = true
311292 t .AddChild (node )
312293 } else {
313- node .parseAny ("" , scene , val . Interface () , isSelect )
294+ node .parseAny ("" , scene , val , isSelect )
314295 t .AddChild (node )
315296 }
316297 }
0 commit comments