5d9b7282ab
2021/1/4 :reflectM包添加indirect处理指针和非指针,获取type、value
26 lines
551 B
Go
26 lines
551 B
Go
/*
|
||
* @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
|
||
}
|