diff --git a/utils/merge.go b/utils/merge.go new file mode 100644 index 0000000..cfb10ac --- /dev/null +++ b/utils/merge.go @@ -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) + } + } +}