mergo icon indicating copy to clipboard operation
mergo copied to clipboard

Readme showcasing mergo.Merge() is actually showing mergo.MergeWithOverwrite() functionality

Open frobones opened this issue 3 years ago • 1 comments

The demo code in the readme showcasing mergo.Merge()

package main

import (
	"fmt"
	"github.com/imdario/mergo"
)

type Foo struct {
	A string
	B int64
}

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

is actually using mergo.MergeWithOverwrite()

frobones avatar Apr 29 '21 20:04 frobones

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 29 '21 20:04 xscode-auto-reply[bot]

Sorry, it's not the case. dest after merge contains its A field untouched - with value two - and B with value 2 from src.B. Overwrite would leave A with the same as src.A.

darccio avatar Sep 11 '23 11:09 darccio