Skip to content

Commit

Permalink
Make "OverwriteWithEmptyValue" in config struct to be set by any meth…
Browse files Browse the repository at this point in the history
…od. (#133)

Make "OverwriteWithEmptyValue" in config struct to be set by any method.

this make the merge more customizable. In cases, where request toggles a boolean value and the the request message can change a "true" value to false we can pass the flag to merge accordingly, which is not possible otherwise.
  • Loading branch information
komalsinha-g authored and vdemeester committed Jan 17, 2020
1 parent e13275d commit 0856b60
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
typeCheck := config.TypeCheck
overwriteWithEmptySrc := config.overwriteWithEmptyValue
overwriteSliceWithEmptySrc := config.overwriteSliceWithEmptyValue
config.overwriteWithEmptyValue = false

if !src.IsValid() {
return
Expand Down Expand Up @@ -246,6 +245,11 @@ func WithOverride(config *Config) {
config.Overwrite = true
}

// WithOverwriteWithEmptyValue will make merge override non empty dst attributes with empty src attributes values.
func WithOverwriteWithEmptyValue(config *Config) {
config.overwriteWithEmptyValue = true
}

// WithOverride will make merge override empty dst slice with empty src slice.
func WithOverrideEmptySlice(config *Config) {
config.overwriteSliceWithEmptyValue = true
Expand Down

0 comments on commit 0856b60

Please sign in to comment.