Golang deep copying, THE RIGHT WAY
MIT License
Reprint is a Go library to deep copy any object THE RIGHT WAY ™️
Unlike most libraries out there, this one deep copies by assigning new pointers to all data structures nested in a given object, hence doing it THE RIGHT WAY ™️
It works with slices, arrays, maps, pointers, nested pointers, nils, structs (with unexported fields too), functions and channels.
Limits:
go get -u github.com/qdm12/reprint
You can check out Golang Playground and activate Imports at the top, or read this:
package main
import (
"fmt"
"github.com/qdm12/reprint"
)
func main() {
one := 1
two := 2
type myType struct{ A *int }
// reprint.FromTo usage:
var x, y myType
x.A = &one
reprint.FromTo(&x, &y) // you can check the error returned also
y.A = &two
fmt.Println(x.A, *x.A) // 0xc0000a0010 1
fmt.Println(y.A, *y.A) // 0xc0000a0018 2
// reprint.This usage:
x2 := myType{&one}
out := reprint.This(x2)
y2 := out.(myType)
y2.A = &two
fmt.Println(x2.A, *x2.A) // 0xc0000a0010 1
fmt.Println(y2.A, *y2.A) // 0xc0000a0018 2
}
F1
and select Remote-Containers: Open Folder in Container...
FromTo
forceCopyValue
might not be needed