https://github.com/ncodes/cstructs
Copy values from a source struct to another similar struct.
https://github.com/ncodes/cstructs
Last synced: about 2 months ago
JSON representation
Copy values from a source struct to another similar struct.
- Host: GitHub
- URL: https://github.com/ncodes/cstructs
- Owner: ncodes
- License: mit
- Created: 2017-03-18T17:04:55.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-20T09:18:51.000Z (about 9 years ago)
- Last Synced: 2024-06-20T06:27:38.350Z (almost 2 years ago)
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
### CStruct
CStruct copies a source struct to another struct that share similar fields
and field types.
#### Installation
```
go get github.com/ncodes/cstructs
```
#### Example
```go
package main
import "github.com/ncodes/cstructs"
// A
type A struct {
Name string
Age int
About []byte
}
// B
type B struct {
Name string
Age int
About []byte
}
func main(){
ben := A{
Name: "benedith",
Age: 20,
About: []byte("Ben is a great sports person"),
}
var pete B
cstructs.Copy(&ben, &pete)
}
```
#### CopySlice(src interface{}, dest interface{})
Copies a slice of struct to another slice of struct. Both slice must have the same length.If src is empty, `nil` is returned.
#### MakeSliceOf(of interface{}, size int)
A convenience method for creating a slice of an initialized type. Useful when there is need to create a slice of struct to use as destination when calling `CopySlice`.