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

Merge arrays: Can't merge maps inside array #204

Open
anveshcsgi opened this issue Jan 20, 2022 · 2 comments
Open

Merge arrays: Can't merge maps inside array #204

anveshcsgi opened this issue Jan 20, 2022 · 2 comments

Comments

@anveshcsgi
Copy link

anveshcsgi commented Jan 20, 2022

eg: Merge with WithOverride

package main

import (
	"fmt"

	"github.com/imdario/mergo"
)

type Foo map[string]interface{}

func main() {

	src := Foo{
		"partners": []map[string]interface{}{
			{

				"common":  "common_field",
				"enabled": true,
			},
			{
				"name":    "new_src_element",
				"enabled": false,
			},
		},
	}
	dest := Foo{
		"partners": []map[string]interface{}{
			{
				"common":  "common_field",
				"enabled": false,
			},
			{
				"name":    "new_dest_element",
				"enabled": false,
			},
		},
	}
	mergo.Merge(&dest, src, mergo.WithOverride)
	fmt.Println(dest)
}

got Output
map[partners:[map[common:common_field enabled:true] map[enabled:false name:new_src_element]]]

Expected Output

map[partners:[map[common:common_field enabled:true] map[enabled:false name:new_dest_element] map[enabled:false name:new_src_element]]]

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@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

@darccio
Copy link
Owner

darccio commented Sep 11, 2023

This will be fixed in v2.

@darccio darccio added the v2 label Sep 11, 2023
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