Skip to content
/ gocopy Public

golang copy slice to slice, map to map, struct to struct, struct to map or bson.M

License

Notifications You must be signed in to change notification settings

young2j/gocopy

Repository files navigation

GoCopy

Github top language Github language count Repository size License Github forks Github stars

About   |   Features   |   Requirements   |   Installation   |   API   |   Benchmark  


😡😡😡Dumping nuclear wastewater into the ocean, damn it! 💣🗾💥😤😤😤

🎯 About

GoCopy is a simple golang repo for copying slice to slice, map to map, struct to struct, struct to map or bson.M.

✨ Features

​ :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

✅ Requirements

​ golang >=1.16

🛠️ Installation

go get -u github.com/young2j/gocopy@latest

🔌 API

  • 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 .

🍻 Related repository

🔥 Benchmark

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

📝 License

This project is under license from MIT. For more details, see the LICENSE file.

Made with ❤️ by young2j

About

golang copy slice to slice, map to map, struct to struct, struct to map or bson.M

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages