About | Features | Requirements | Installation | API | Benchmark
😡😡😡Dumping nuclear wastewater into the ocean, damn it! 💣🗾💥😤😤😤
GoCopy is a simple golang repo for copying slice to slice, map to map, struct to struct, struct to map or bson.M.
:heavy_check_mark: copy slice to slice by type
:heavy_check_mark: copy map to map by type
:heavy_check_mark: copy struct to struct by field name
:heavy_check_mark: copy struct to map/bson.M by field name
:heavy_check_mark: support append values, change filed-case, rename or ignore any field when copying
:heavy_check_mark: support customized convert function to transform any filed to what you want
golang >=1.16
go get -u github.com/young2j/gocopy@latest
Copy(to, from interface{})
CopyWithOption(to,from interface{},opt *Option)
Note: The arg
to
must be a reference value(usually&to
), or copy maybe fail.
see more at ./example
# path/to/example
$ go run .
go test -v . -bench=. -benchmem -benchtime=1s -cpu=4
goos: darwin
goarch: amd64
pkg: github.com/young2j/gocopy
cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
BenchmarkCopy
BenchmarkCopy-4 122139 8884 ns/op 5592 B/op 81 allocs/op
BenchmarkCopier
BenchmarkCopier-4 62940 18695 ns/op 14640 B/op 166 allocs/op
PASS
ok github.com/young2j/gocopy 4.999s
This project is under license from MIT. For more details, see the LICENSE file.
Made with ❤️ by young2j