https://github.com/joegasewicz/butter
Merge Go structs
https://github.com/joegasewicz/butter
go structs structs-go
Last synced: about 1 year ago
JSON representation
Merge Go structs
- Host: GitHub
- URL: https://github.com/joegasewicz/butter
- Owner: joegasewicz
- License: mit
- Created: 2022-10-19T23:03:50.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-20T00:25:45.000Z (over 3 years ago)
- Last Synced: 2025-02-10T14:53:20.313Z (about 1 year ago)
- Topics: go, structs, structs-go
- Language: Go
- Homepage: https://pkg.go.dev/github.com/joegasewicz/butter
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Butter
Merge Go structs
### Install
```
go get -u github.com/joegasewicz/butter
```
#### Merge 2 structs & return a map
Create a map of the combined results of two structs. The returned map
will merge the incoming struct on top of the original struct.
The returned map is useful as a value to GORM's `Updates` method for example.
```go
type user struct {
ID uint
Name string
Msg string
}
incoming := user{
Name: "joe",
}
original := user{
ID: 1,
Msg: "hello!",
}
merged := butter.MergeStructsToMap(original, incoming)
// returns
// ID -> 1
// Name -> Joe
// Description -> hello!
// Not we could pass the result to GORM's `Updates` method
db.Model(&user).Updates(merged)
```