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<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 be faster as well because no reflection is required.
>
> As far as I know Kubernetes uses this approach and they have a 
> code-generator which can conveniently generate the code for the structs.
>
> https://github.com/kubernetes/code-generator/tree/master/cmd/deepcopy-gen
>
>
>
> On Fri, Apr 17, 2020 at 2:07 PM Carsten Orthbandt <carsten....@gmail.com> 
> wrote:
>
>> 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 automatic.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/17810cd4-dab5-4583-8944-aed38b773232%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/17810cd4-dab5-4583-8944-aed38b773232%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/573fca81-61b0-4e32-b051-4a7bcdb2f6f1n%40googlegroups.com.

Reply via email to