Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite struct's field with corresponding map's key that is intended to be zero #85

Merged
merged 2 commits into from
Jan 23, 2019

Conversation

requilence
Copy link
Contributor

@requilence requilence commented Jun 15, 2018

Details here: #84

In order to make deepMerge func know that it the src value was specially indicated in the source map(key exists) we need to pass some flag to it. And set this flag in case deepMerge while going through the source map keys.

One variant is to Implement unexported overwriteWithEmptyValue in the Config. So there is no need to extend deepMerge.

I have also wrote some basic tests

Allow to overwrite struct field with empty value in case corresponding source map's key exists and indicated to zero-value
@requilence requilence changed the title Fixes #84 Closes #84 Jun 15, 2018
@requilence requilence changed the title Closes #84 Overwrite struct's field with corresponding map's key that is intended to be zero Jun 15, 2018
@darccio darccio changed the base branch from master to pr-85 January 23, 2019 23:24
@darccio darccio merged commit f245ea6 into darccio:pr-85 Jan 23, 2019
@darccio
Copy link
Owner

darccio commented Jan 23, 2019

Checking if it passes all the tests.

@darccio
Copy link
Owner

darccio commented Jan 23, 2019

It works. Merged.

@@ -72,6 +72,7 @@ func deepMap(dst, src reflect.Value, visited map[uintptr]*visit, depth int, conf
case reflect.Struct:
srcMap := src.Interface().(map[string]interface{})
for key := range srcMap {
config.overwriteWithEmptyValue = true
Copy link

@liggitt liggitt Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the continue or return cases are hit below without calling deepMerge (which would have reset to false), this results in mutating config and setting overwriteWithEmptyValue=true that can affect other calls to deepMerge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants