From 5a830c9bef84409410e059213134d9a734f9d8a0 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Sat, 3 Aug 2024 09:53:08 +0300 Subject: [PATCH] Create util package --- utils/merge.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 utils/merge.go 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) + } + } +}