https://github.com/davidwartell/go-copier
I am the best go struct copier. I even have extensive support for copying protobuf structs and protobuf wrappers.
https://github.com/davidwartell/go-copier
copy-structs deepcopy go golang grpc grpc-go protobuf struct-copier structtags
Last synced: 2 months ago
JSON representation
I am the best go struct copier. I even have extensive support for copying protobuf structs and protobuf wrappers.
- Host: GitHub
- URL: https://github.com/davidwartell/go-copier
- Owner: davidwartell
- License: apache-2.0
- Created: 2022-09-28T21:56:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-09T15:20:12.000Z (about 2 years ago)
- Last Synced: 2024-06-20T12:51:50.169Z (almost 2 years ago)
- Topics: copy-structs, deepcopy, go, golang, grpc, grpc-go, protobuf, struct-copier, structtags
- Language: Go
- Homepage:
- Size: 35.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-copier
I am a struct copier. I copy everything I can and copy more than https://github.com/jinzhu/copier. I also have support for
protobuf wrappers.
* Copy from field to field with same name
* Copy from slice to slice
* Copy from pointer to non-pointer of same or compatible type
* Copy from map to map
* Ignore a field with a tag
* Map a field with different names with a tag
* Deep Copy
* Copy from encoding.TextMarshaler to string
* Copy from string to encoding.TextUnmarshaler
* Support type aliases and string enums
* Override Marshal behavior with CopierMarshaler
* Override UnMarshal behavior with CopierUnmarshal
* Copy between unsigned int and *int types (e.g. uint16 to uint32)
* Copy between signed int and *int types (e.g. int16 to int32)
* Copy timestamppb.Timestamp to time.Time and *time.Time
* Copy time.Time and *time.Time to timestamppb.Timestamp
* Copy durationpb.Duration to time.Duration and *time.Duration
* Copy time.Duration and *time.Duration to durationpb.Duration
* Copy from wrapperspb.StringValue to string and *string
* Copy from string and *string to wrapperspb.StringValue
* Copy from wrapperspb.BoolValue to bool and *bool
* Copy from bool and *bool to wrapperspb.BoolValue
* Copy from wrapperspb.Int32Value to any signed integer or signed integer pointer
* Copy from any signed integer or signed integer pointer to wrapperspb.Int32Value
* Copy from wrapperspb.Int64Value to any signed integer or signed integer pointer
* Copy from any signed integer or signed integer pointer to wrapperspb.Int64Value
* Copy from wrapperspb.UInt32Value to any unsigned integer or unsigned integer pointer
* Copy from any unsigned integer or unsigned integer pointer to wrapperspb.UInt32Value
* Copy from wrapperspb.UInt64Value to any unsigned integer or unsigned integer pointer
* Copy from any unsigned integer or unsigned integer pointer to wrapperspb.UInt64Value
* Copy from wrapperspb.FloatValue to any float or float pointer
* Copy from any float or float pointer to wrapperspb.FloatValue
* Copy from wrapperspb.DoubleValue to any float or float pointer
* Copy from any float or float pointer to wrapperspb.DoubleValue
* Copy from wrapperspb.BytesValue to []byte
* Copy from []byte to wrapperspb.BytesValue
## Usage
```
err := copier.Copy(dstStructPtr, srcStructPtr)
```
See copier_test.go for more
### Unit Tests
```
make test
```
* Linter
Requires golangci-lint.
```
brew install golangci/tap/golangci-lint
make golint
```
* Security Linter
```
make gosec
```
## Contributing
Happy to accept PRs.
# Author
**davidwartell**
*
*
## License
Released under the [Apache License](https://github.com/davidwartell/go-copier/blob/master/LICENSE).