jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.58k stars 489 forks source link

feat: Copy to Nil pointer of struct #210

Open zedisdog opened 7 months ago

zedisdog commented 7 months ago
type struct1 struct {
    A int
}

type struct2 struct {
    A int
}

s1 := struct1{A: 1}
var s2 *struct2

err := copier.Copy(&s2, s1)
if err != nil {
    t.Error("should not error")
}
if s1.A != (*s2).A {
    t.Error("should equal")
}