Re: [go-nuts] Re: DeepCloning a datastructure

2022-05-06 Thread Zhaoxun Yan
Yes there are two open source packages regarding "DeepCopy" https://github.com/mohae/deepcopy/ https://github.com/barkimedes/go-deepcopy/ Has anyone tried them yet? 在2020年4月19日星期日 UTC+8 01:26:11 写道: > How about doing it manually? You can define a DeepCopy method on the type > and manually allo

Re: [go-nuts] Re: DeepCloning a datastructure

2020-04-18 Thread Ankit R Gadiya
How about doing it manually? You can define a DeepCopy method on the type and manually allocate a new struct and initialize the maps and slices by looping over them. That way you get to have more control over all the fields and problem of private fields is solved as well. I would guess this would b

[go-nuts] Re: DeepCloning a datastructure

2020-04-17 Thread Carsten Orthbandt
The easiest way is to marshal everything into some sort of byte slice, then unmarshal back. JSON doesn't work for this if there are private fields. But gotiny (https://github.com/niubaoshu/gotiny) does. If you use interfaces in your data, you have to register their types, everthing else is autom