mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-02 07:54:19 +08:00
1
This commit is contained in:
parent
c16a994fd4
commit
0c9ca254e6
@ -6,21 +6,6 @@ import (
|
||||
"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) {
|
||||
if isBaseNil(from) {
|
||||
return
|
||||
@ -40,6 +25,21 @@ func setBaseValue(from, to reflect.Value) {
|
||||
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) {
|
||||
if !to.CanSet() {
|
||||
return
|
||||
@ -47,6 +47,9 @@ func copyAny(from, to reflect.Value) {
|
||||
if isBaseNil(from) {
|
||||
return
|
||||
}
|
||||
if isBaseNil(to) {
|
||||
to.Set(getBaseZeroValue(to.Type()))
|
||||
}
|
||||
btfrom := baseType(from.Type())
|
||||
btto := baseType(to.Type())
|
||||
if typeEq(btfrom, btto) {
|
||||
@ -118,6 +121,15 @@ func baseType(t reflect.Type) reflect.Type {
|
||||
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 {
|
||||
return t1.String() == t2.String()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user