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

Override value with empty struct #185

Closed
funkycode opened this issue Apr 5, 2021 · 1 comment
Closed

Override value with empty struct #185

funkycode opened this issue Apr 5, 2021 · 1 comment

Comments

@funkycode
Copy link

original map:

map[string]interface {}{"global":map[interface {}]interface {}{"loadbalancer":map[interface {}]interface {}{"internal":map[interface {}]interface {}{}, "type":"vip", "vip":map[interface {}]interface {}{"ip":"127.0.0.1"}}}}

As yaml:

global:
  loadbalancer:
    internal: {}
    type: vip
    vip:
      ip: 127.0.0.1

override map:

map[string]interface {}{"global":map[interface {}]interface {}{"loadbalancer":map[interface {}]interface {}{"internal":map[interface {}]interface {}{"ip":[]interface {}{"127.0.0.1"}}, "type":"internal", "vip":map[interface {}]interface {}{}}}}

as yaml:

global:
  loadbalancer:
    type: internal
    internal:
      ip:
      - 127.0.0.1
    vip: {}

merged map:

map[string]interface {}{"global":map[interface {}]interface {}{"loadbalancer":map[interface {}]interface {}{"internal":map[interface {}]interface {}{"ip":[]interface {}{"127.0.0.1"}}, "type":"internal", "vip":map[interface {}]interface {}{"ip":"127.0.0.1"}}}}

As yaml:

global:
  loadbalancer:
    type: internal
    internal:
      ip:
      - 127.0.0.1
    vip:
      ip: 127.0.0.1

As you can see the both vip and internal are both kept while i override map has one of the declared as empty.

I tried both
mergo.Merge(&origProfile, overrideProfile, mergo.WithOverwriteWithEmptyValue)
and
mergo.Merge(&origProfile, overrideProfile, mergo.WithOverwrite)

@xscode-auto-reply
Copy link

Thanks for opening a new issue. The team has been notified and will review it as soon as possible.
For urgent issues and priority support, visit https://xscode.com/imdario/mergo

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

No branches or pull requests

2 participants