How to overwrite specified field with empty value in struct
elinxz opened this issue · comments
colorline commented
I just want to overwrite the value of the specified field of type string, is there any way to make it.
type MergeData struct {
A string `json:"a"` // overwrite with empty value
B string `json:"b"` // overwrite with non-empty value
}
func TestA(t *testing.T) {
src := &MergeData{
A: "",
B: "",
}
dst := &MergeData{
A: "a",
B: "b",
}
err := mergo.Merge(dst, src, mergo.WithOverride)
if err != nil {
panic(err)
}
t.Log(dst)
}
How to get {"", "b"}?
Dario Castañé commented
Mergo doesn't support, and won't in the mid term, a selective merging operation like this.