https://github.com/iqbalmind/go-deepcopy
A reflection-based deep copy library for Go. Supports structs, slices, maps, arrays, pointers, interfaces, and channels.
https://github.com/iqbalmind/go-deepcopy
clone deepcopy golang library reflection
Last synced: 9 months ago
JSON representation
A reflection-based deep copy library for Go. Supports structs, slices, maps, arrays, pointers, interfaces, and channels.
- Host: GitHub
- URL: https://github.com/iqbalmind/go-deepcopy
- Owner: IqbalMind
- License: mit
- Created: 2025-09-22T06:44:23.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-22T07:46:17.000Z (9 months ago)
- Last Synced: 2025-09-22T09:23:16.446Z (9 months ago)
- Topics: clone, deepcopy, golang, library, reflection
- Language: Go
- Homepage: https://pkg.go.dev/github.com/iqbalmind/go-deepcopy
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-deepcopy
[](https://pkg.go.dev/github.com/iqbalmind/go-deepcopy)
[](https://goreportcard.com/report/github.com/iqbalmind/go-deepcopy)
A simple reflection-based **deep copy library for Go**, supporting:
- Structs
- Pointers
- Slices
- Maps
- Arrays
- Interfaces
- Channels
## ๐ Installation
```bash
go get github.com/iqbalmind/go-deepcopy
```
## ๐ Usage
```go
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:
```bash
Original: Dewi Jl. Braga No. 99
Cloned: Budi Jl. Asia Afrika No. 45
```
## ๐งช Running Tests
``go
go test -v
``
## ๐ License
MIT ยฉ 2025 [iqbalmind](https://github.com/iqbalmind)