mergo icon indicating copy to clipboard operation
mergo copied to clipboard

Details on which fields/attributes were updated

Open jankrynauw opened this issue 2 years ago • 3 comments

Hi, is there perhaps a way to see which fields have been updated after a merge?

jankrynauw avatar Aug 30 '21 21:08 jankrynauw

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 Aug 30 '21 21:08 xscode-auto-reply[bot]

Is this something that is of relevance to this project @imdario? If so, I am happy to contribute to this.

To expand on my understanding of what @jankrynauw is seeking using the demo:

src := Foo{
	A: "one",
	B: 2,
}
dest := Foo{
	A: "two",
}
mergo.Merge(&dest, src)
fmt.Println(dest)
// Will print
// {two 2}

It would be useful to have a way to know that field A comes from dest and field B from src.

My suggestion would be to have a map[string]string with the keys being the struct's field paths and the value being the name of the relevant struct. In this example:

map[string]int32{
	"A":       "dest",
	"B":      "src",
}

ruanspies avatar Apr 06 '22 09:04 ruanspies

@ruanspies Not sure about this change.

darccio avatar Apr 22 '22 15:04 darccio

Closing. Maybe it could be considered for v2, but I don't see a real value that outweights the effort to track all merges.

darccio avatar Sep 11 '23 11:09 darccio