gref is a utility library in Golang that utilizes reflection for data assignment. The main function is to assign values between two parameters, such as two different structs.
go get github.com/zy1024/gref
The Copy(src,dst)
function requires two pointers, such as pointers to structs or slices. It will use reflection to assign the value of src to dst. The assignment of structs is based on matching field names, and only non-empty fields in dst will be assigned.
Support for basic data types, structs, Pointers, slices.
More efficient than traditional json.Marshal and json.Unmarshal methods. With the same data, the efficiency is about 3-4 times.
The sample code can be seen in the TestCopy
method in example_test.go
.
Official release, supporting assignment operations for structs, pointers, slices, and basic data types.
- Add support for other types, such as channel and map.