mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
dynamic: invert if
Signed-off-by: c9s <yoanlin93@gmail.com>
This commit is contained in:
parent
b15e8d0ce4
commit
903d773025
|
@ -24,14 +24,17 @@ func MergeStructValues(dst, src interface{}) {
|
|||
}
|
||||
|
||||
// if there is a field with the same name
|
||||
if fieldSrcType, ok := srcStructType.FieldByName(fieldName); ok {
|
||||
// ensure that the type is the same
|
||||
if fieldSrcType.Type == fieldType.Type {
|
||||
srcValue := reflect.ValueOf(src).Elem().FieldByName(fieldName)
|
||||
dstValue := reflect.ValueOf(dst).Elem().FieldByName(fieldName)
|
||||
if (fieldType.Type.Kind() == reflect.Ptr && dstValue.IsNil()) || dstValue.IsZero() {
|
||||
dstValue.Set(srcValue)
|
||||
}
|
||||
fieldSrcType, found := srcStructType.FieldByName(fieldName)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
|
||||
// ensure that the type is the same
|
||||
if fieldSrcType.Type == fieldType.Type {
|
||||
srcValue := reflect.ValueOf(src).Elem().FieldByName(fieldName)
|
||||
dstValue := reflect.ValueOf(dst).Elem().FieldByName(fieldName)
|
||||
if (fieldType.Type.Kind() == reflect.Ptr && dstValue.IsNil()) || dstValue.IsZero() {
|
||||
dstValue.Set(srcValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user