Mergo is intended to assign **only** zero value fields on destination with source value. Since April 6th it works like this. Before it didn't work properly, causing some random overwrites. After some issues and PRs I found it didn't merge as I designed it. Thanks to [imdario/mergo#8](https://github.com/imdario/mergo/pull/8) overwriting functions were added and the wrong behavior was clearly detected.
If you were using Mergo **before** April 6th 2015, please check your project works as intended after updating your local copy with ```go get -u github.com/imdario/mergo```. I apologize for any issue caused by its previous behavior and any future bug that Mergo could cause (I hope it won't!) in existing projects after the change (release 0.2.0).
t.Fatalf("pt not merged in properly: bpt.B.Value(%d) != pt.B.Value(%d)",bpt.B.Value,pt.B.Value)
}
}
typestructWithTimePointerstruct{
Birth*time.Time
}
funcTestTime(t*testing.T){
now:=time.Now()
dataStruct:=structWithTimePointer{
Birth:&now,
}
dataMap:=map[string]interface{}{
"Birth":&now,
}
b:=structWithTimePointer{}
iferr:=Merge(&b,dataStruct);err!=nil{
t.FailNow()
}
ifb.Birth.IsZero(){
t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataStruct['Birth'](%v)",b.Birth,dataStruct.Birth)
}
ifb.Birth!=dataStruct.Birth{
t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataStruct['Birth'](%v)",b.Birth,dataStruct.Birth)
}
b=structWithTimePointer{}
iferr:=Map(&b,dataMap);err!=nil{
t.FailNow()
}
ifb.Birth.IsZero(){
t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataMap['Birth'](%v)",b.Birth,dataMap["Birth"])
}
}
typesimpleNestedstruct{
Aint
}
typestructWithNestedPtrValueMapstruct{
NestedPtrValuemap[string]*simpleNested
}
funcTestNestedPtrValueInMap(t*testing.T){
src:=&structWithNestedPtrValueMap{
NestedPtrValue:map[string]*simpleNested{
"x":{
A:1,
},
},
}
dst:=&structWithNestedPtrValueMap{
NestedPtrValue:map[string]*simpleNested{
"x":{},
},
}
iferr:=Map(dst,src);err!=nil{
t.FailNow()
}
ifdst.NestedPtrValue["x"].A==0{
t.Fatalf("Nested Ptr value not merged in properly: dst.NestedPtrValue[\"x\"].A(%v) != src.NestedPtrValue[\"x\"].A(%v)",dst.NestedPtrValue["x"].A,src.NestedPtrValue["x"].A)
t.Fatalf("pt not merged properly: bpt.B.Value(%d) != pt.B.Value(%d)",bpt.B.Value,pt.B.Value)