fin-check-api/utils/merge.go

20 lines
335 B
Go
Raw Normal View History

2024-08-03 08:53:08 +02:00
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)
}
}
}