mergo icon indicating copy to clipboard operation
mergo copied to clipboard

Override value with empty struct

Open funkycode opened this issue 3 years ago • 1 comments

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)

funkycode avatar Apr 05 '21 08:04 funkycode

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

xscode-auto-reply[bot] avatar Apr 05 '21 08:04 xscode-auto-reply[bot]