deepcopy

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 1 Imported by: 0

README ¶

go-deepcopy

Go Reference Go Report Card

A simple reflection-based deep copy library for Go, supporting:

  • Structs
  • Pointers
  • Slices
  • Maps
  • Arrays
  • Interfaces
  • Channels

🚀 Installation

go get github.com/iqbalmind/go-deepcopy

📖 Usage

package main

import (
    "fmt"
    "github.com/iqbalmind/go-deepcopy"
)

type Address struct {
    Street string
    City   string
}

type Person struct {
    Name    string
    Age     int
    Address *Address
}

func main() {
    original := Person{
        Name: "Dewi",
        Age:  28,
        Address: &Address{
            Street: "Jl. Braga No. 99",
            City:   "Bandung",
        },
    }

    cloned, _ := deepcopy.DeepCopy(original)
    clonedPerson := cloned.(Person)

    // Modify the cloned struct
    clonedPerson.Name = "Budi"
    clonedPerson.Address.Street = "Jl. Asia Afrika No. 45"

    fmt.Println("Original:", original.Name, original.Address.Street)
    fmt.Println("Cloned:", clonedPerson.Name, clonedPerson.Address.Street)
}

Output:

Original: Dewi Jl. Braga No. 99
Cloned:   Budi Jl. Asia Afrika No. 45

🧪 Running Tests

go go test -v

📜 License

MIT © 2025 iqbalmind

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func DeepCopy ¶

func DeepCopy(src interface{}) (interface{}, error)

DeepCopy performs a deep copy of any value using reflection. It returns a new, independent copy of the original value.

Types ¶

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL