Deecpy, The DeepCopy Library
package main
import (
"fmt"
"v8.run/go/deecpy"
)
// func deecpy.Copy[T any](dst, src *T) error
// func deecpy.Duplicate[T any](src T) (T, error)
type Person struct {
Name string
Age int
id ID
}
type ID struct {
UUID string
email string
}
var john = Person{Name: "John", Age: 30, id: ID{UUID: "123", email: "john@example.com"}}
var jane = Person{Name: "Jane", Age: 25, id: ID{UUID: "456", email: "jane@example.com"}}
func main() {
var john_copy Person
err := deecpy.Copy(&john_copy, &john)
if err != nil {
panic(err)
}
fmt.Println("john:", john)
fmt.Println("john_copy:", john_copy)
jane_copy, err := deecpy.Duplicate(jane)
if err != nil {
panic(err)
}
fmt.Println("jane:", jane)
fmt.Println("jane_copy:", jane_copy)
}