feat(Go-Tool):

2021/1/4 :reflectM包添加indirect处理指针和非指针,获取type、value
This commit is contained in:
Huangzj
2021-01-04 15:49:21 +08:00
parent eb50b6273b
commit 5d9b7282ab
3 changed files with 85 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
/*
* @Author : huangzj
* @Time : 2021/1/4 15:44
* @Description
*/
package reflectM
import "reflect"
//获取value值,包含ptr的处理
func Indirect(reflectValue reflect.Value) reflect.Value {
for reflectValue.Kind() == reflect.Ptr {
reflectValue = reflectValue.Elem()
}
return reflectValue
}
//获取Type值,包含ptr的处理
func IndirectType(reflectType reflect.Type) reflect.Type {
for reflectType.Kind() == reflect.Ptr || reflectType.Kind() == reflect.Slice {
reflectType = reflectType.Elem()
}
return reflectType
}