https://github.com/groob/map-to-struct
https://github.com/groob/map-to-struct
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/groob/map-to-struct
- Owner: groob
- Created: 2017-04-04T02:48:12.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-04T02:48:52.000Z (about 8 years ago)
- Last Synced: 2025-01-30T08:30:54.312Z (4 months ago)
- Language: Go
- Size: 0 Bytes
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Convert a Go `map[string]string` type to a struct.
This utility is not supposed to be a complete solution but rather a simple tool to save a lot of typing when creating map-to-struct conversions.# Install
```
go get -u github.com/groob/map-to-struct
```# Usage
`map-to-struct` expects a json object at stdin.
```
osqueryi --json 'select * from os_version'|jq '.[0]' | map-to-structif v, ok := osMap["minor"]; ok {
goStruct.Minor = v
}if v, ok := osMap["name"]; ok {
goStruct.Name = v
}if v, ok := osMap["patch"]; ok {
goStruct.Patch = v
}if v, ok := osMap["platform"]; ok {
goStruct.Platform = v
}if v, ok := osMap["version"]; ok {
goStruct.Version = v
}if v, ok := osMap["build"]; ok {
goStruct.Build = v
}if v, ok := osMap["codename"]; ok {
goStruct.Codename = v
}if v, ok := osMap["major"]; ok {
goStruct.Major = v
}if v, ok := osMap["platform_like"]; ok {
goStruct.PlatformLike = v
}
```