Fix conversion to pointer
This commit is contained in:
parent
1269203c08
commit
7ef9e56505
@ -38,10 +38,16 @@ func Convert(in reflect.Value, toType reflect.Type) (reflect.Value, error) {
|
|||||||
|
|
||||||
// If the output type is a pointer to the input type
|
// If the output type is a pointer to the input type
|
||||||
if reflect.PtrTo(inType) == toType {
|
if reflect.PtrTo(inType) == toType {
|
||||||
|
if in.CanAddr() {
|
||||||
// Return pointer to input
|
// Return pointer to input
|
||||||
return in.Addr(), nil
|
return in.Addr(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inPtrVal := reflect.New(inType)
|
||||||
|
inPtrVal.Elem().Set(in)
|
||||||
|
return inPtrVal, nil
|
||||||
|
}
|
||||||
|
|
||||||
// If input is a pointer pointing to the output type
|
// If input is a pointer pointing to the output type
|
||||||
if inType.Kind() == reflect.Ptr && inType.Elem() == toType {
|
if inType.Kind() == reflect.Ptr && inType.Elem() == toType {
|
||||||
// Return value being pointed at by input
|
// Return value being pointed at by input
|
||||||
|
Reference in New Issue
Block a user