|
|
@ -6,21 +6,6 @@ import (
|
|
|
|
"reflect"
|
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func CopyAny(from, to interface{}) {
|
|
|
|
|
|
|
|
t := reflect.ValueOf(to)
|
|
|
|
|
|
|
|
if t.Kind() == reflect.Ptr {
|
|
|
|
|
|
|
|
t = t.Elem()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !t.CanSet() {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f := reflect.ValueOf(from)
|
|
|
|
|
|
|
|
if isBaseNil(f) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
copyAny(f, t)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setBaseValue(from, to reflect.Value) {
|
|
|
|
func setBaseValue(from, to reflect.Value) {
|
|
|
|
if isBaseNil(from) {
|
|
|
|
if isBaseNil(from) {
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -40,6 +25,21 @@ func setBaseValue(from, to reflect.Value) {
|
|
|
|
to.Set(v)
|
|
|
|
to.Set(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func CopyAny(from, to interface{}) {
|
|
|
|
|
|
|
|
t := reflect.ValueOf(to)
|
|
|
|
|
|
|
|
if t.Kind() == reflect.Ptr {
|
|
|
|
|
|
|
|
t = t.Elem()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !t.CanSet() {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f := reflect.ValueOf(from)
|
|
|
|
|
|
|
|
if isBaseNil(f) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
copyAny(f, t)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func copyAny(from, to reflect.Value) {
|
|
|
|
func copyAny(from, to reflect.Value) {
|
|
|
|
if !to.CanSet() {
|
|
|
|
if !to.CanSet() {
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -47,6 +47,9 @@ func copyAny(from, to reflect.Value) {
|
|
|
|
if isBaseNil(from) {
|
|
|
|
if isBaseNil(from) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if isBaseNil(to) {
|
|
|
|
|
|
|
|
to.Set(getBaseZeroValue(to.Type()))
|
|
|
|
|
|
|
|
}
|
|
|
|
btfrom := baseType(from.Type())
|
|
|
|
btfrom := baseType(from.Type())
|
|
|
|
btto := baseType(to.Type())
|
|
|
|
btto := baseType(to.Type())
|
|
|
|
if typeEq(btfrom, btto) {
|
|
|
|
if typeEq(btfrom, btto) {
|
|
|
@ -118,6 +121,15 @@ func baseType(t reflect.Type) reflect.Type {
|
|
|
|
return t
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func baseLayer(t reflect.Type) int {
|
|
|
|
|
|
|
|
var layer int
|
|
|
|
|
|
|
|
for t.Kind() == reflect.Ptr {
|
|
|
|
|
|
|
|
layer++
|
|
|
|
|
|
|
|
t = t.Elem()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return layer
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func typeEq(t1, t2 reflect.Type) bool {
|
|
|
|
func typeEq(t1, t2 reflect.Type) bool {
|
|
|
|
return t1.String() == t2.String()
|
|
|
|
return t1.String() == t2.String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|