Create util package
This commit is contained in:
parent
52ce4a181b
commit
5a830c9bef
19
utils/merge.go
Normal file
19
utils/merge.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func MergeNonZeroFields(src, dest interface{}) {
|
||||
srcVal := reflect.ValueOf(src).Elem()
|
||||
destVal := reflect.ValueOf(dest).Elem()
|
||||
|
||||
for i := 0; i < srcVal.NumField(); i++ {
|
||||
srcField := srcVal.Field(i)
|
||||
destField := destVal.Field(i)
|
||||
|
||||
if !srcField.IsZero() {
|
||||
destField.Set(srcField)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user