Go Reference GitHub Workflow Status (push) Codecov main GitHub license

Deecpy

Deecpy, The DeepCopy Library

Example

package main

import (
    "fmt"

    "github.com/unsafe-risk/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: "[email protected]"}}
var jane = Person{Name: "Jane", Age: 25, id: ID{UUID: "456", email: "[email protected]"}}

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)
}

Go Playground

GitHub

View Github