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.orthba...@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+unsubscr...@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/CADHj4Ne%3D0%3D3HW%3DXL78zAkyKLnWSyLaOT51ei8WWJo_ivpuWg8w%40mail.gmail.com.