util-go/reflect/indirect.go

32 lines
510 B
Go
Raw Permalink Normal View History

package reflect
import (
"reflect"
)
func Indirect(v interface{}) interface{} {
if v == nil {
return nil
}
return IndirectValue(reflect.ValueOf(v)).Interface()
}
2019-01-07 14:35:34 +00:00
func IndirectValue(reflectValue Value) Value {
if reflectValue.Kind() == reflect.Ptr {
return reflectValue.Elem()
}
return reflectValue
}
2019-01-07 14:35:34 +00:00
func IndirectType(reflectType Type) Type {
if reflectType == TypeInvalid {
return TypeInvalid
}
if reflectType.Kind() == reflect.Ptr {
return reflectType.Elem()
}
return reflectType
}