package common import ( "bytes" "encoding/gob" ) // Warning: If src contains a pointer to a zero-valued object, // the pointer will be converted to nil. // such as *string -> nil; *[]string{} -> nil func CopyByGob(dst, src interface{}) error { var buf bytes.Buffer if err := gob.NewEncoder(&buf).Encode(src); err != nil { return err } return gob.NewDecoder(bytes.NewBuffer(buf.Bytes())).Decode(dst) }