https://github.com/mitchellh/mapstructure
Last synced: about 1 month ago
Repository metadata:
Go library for decoding generic map values into native Go structures and vice versa.
- Host: GitHub
- URL: https://github.com/mitchellh/mapstructure
- Owner: mitchellh
- License: mit
- Archived: true
- Created: 2013-05-20T05:24:34.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2024-06-25T15:17:23.000Z (6 months ago)
- Last Synced: 2024-10-29T19:24:29.544Z (about 2 months ago)
- Language: Go
- Homepage: https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
- Size: 357 KB
- Stars: 7,907
- Watchers: 66
- Forks: 672
- Open Issues: 84
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Owner metadata:
- Name: Mitchell Hashimoto
- Login: mitchellh
- Email:
- Kind: user
- Description:
- Website: https://mitchellh.com
- Location: Los Angeles, CA
- Twitter: mitchellh
- Company:
- Icon url: https://avatars.githubusercontent.com/u/1299?u=cc88a733b0c95bdfd323ec661c0da4c6768c4e4b&v=4
- Repositories: 146
- Last Synced at: 2024-04-16T00:03:37.364Z
- Profile URL: https://github.com/mitchellh
- Sponsor URL:
Committers metadata
Last synced: 2 months ago
Total Commits: 236
Total Committers: 67
Avg Commits per committer: 3.522
Development Distribution Score (DDS): 0.381
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
Name | Commits | |
---|---|---|
Mitchell Hashimoto | m****o@g****m | 146 |
Mitchell Hashimoto | x****x@g****m | 5 |
Calvin Leung Huang | c****0@g****m | 4 |
Ryan Uber | ru@r****m | 3 |
Sebastian Widmer | s****r@t****h | 3 |
Akos Gyimesi | g****s@g****m | 2 |
Aleksander Kochetkov | s****4@g****m | 2 |
Gernot Eger | g****r@g****m | 2 |
James Nugent | j****s@j****m | 2 |
Mark Costello | m****k@m****t | 2 |
Matt Keeler | m****7@g****m | 2 |
Shunsuke Suzuki | s****9@g****m | 2 |
Vladimir Skipor | s****r@y****u | 2 |
Zhao Jiangkun | j****o@e****e | 2 |
felipe.ramos | f****s@c****m | 2 |
kevin.lin | k****n@s****m | 2 |
Buğra Özgürsoy | b****r@g****m | 2 |
Daniel Nephin | d****n@g****m | 2 |
Andrew M Bursavich | a****h@g****m | 1 |
Anonymous | a****s@g****m | 1 |
Armon Dadgar | a****r@g****m | 1 |
Arno Geurts | a****s@s****m | 1 |
Beorn Facchini | b****f@g****m | 1 |
Blake Miner | m****e@g****m | 1 |
Bogdan Drutu | b****u@g****m | 1 |
Camden Cheek | c****n@c****m | 1 |
Chavez | n****l@g****m | 1 |
David Lazar | l****d@c****u | 1 |
Dmitri Shuralyov | s****L@g****m | 1 |
Emmanuel Odeke | e****e@g****m | 1 |
and 37 more... |
Issue and Pull Request metadata
Last synced: about 1 month ago
Package metadata
- Total packages: 3
- Total downloads: unknown
- Total docker downloads: 62,915,760,717
- Total dependent packages: 32,864 (may contain duplicates)
- Total dependent repositories: 124,571 (may contain duplicates)
- Total versions: 51
go: github.com/mitchellh/mapstructure
Package mapstructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]interface{} into a native Go structure. The Go structure can be arbitrarily complex, containing slices, other structs, etc. and the decoder will properly decode nested maps and so on into the proper structures in the native Go struct. See the examples to see what the decoder is capable of. The simplest function to start with is Decode. When decoding to a struct, mapstructure will use the field name by default to perform the mapping. For example, if a struct has a field "Username" then mapstructure will look for a key in the source value of "username" (case insensitive). You can change the behavior of mapstructure by using struct tags. The default struct tag that mapstructure looks for is "mapstructure" but you can customize it using DecoderConfig. To rename the key that mapstructure looks for, use the "mapstructure" tag and set a value directly. For example, to change the "username" example above to "user": Embedded structs are treated as if they're another field with that name. By default, the two structs below are equivalent when decoding with mapstructure: This would require an input that looks like below: If your "person" value is NOT nested, then you can append ",squash" to your tag value and mapstructure will treat it as if the embedded struct were part of the struct directly. Example: Now the following input would be accepted: When decoding from a struct to a map, the squash tag squashes the struct fields into a single map. Using the example structs from above: Will be decoded into a map: DecoderConfig has a field that changes the behavior of mapstructure to always squash embedded structs. If there are any unmapped keys in the source value, mapstructure by default will silently ignore them. You can error by setting ErrorUnused in DecoderConfig. If you're using Metadata you can also maintain a slice of the unused keys. You can also use the ",remain" suffix on your tag to collect all unused values in a map. The field with this tag MUST be a map type and should probably be a "map[string]interface{}" or "map[interface{}]interface{}". See example below: Given the input below, Other would be populated with the other values that weren't used (everything but "name"): When decoding from a struct to any other value, you may use the ",omitempty" suffix on your tag to omit that value if it equates to the zero value. The zero value of all types is specified in the Go specification. For example, the zero type of a numeric type is zero ("0"). If the struct field value is zero and a numeric type, the field is empty, and it won't be encoded into the destination type. Since unexported (private) struct fields cannot be set outside the package where they are defined, the decoder will simply skip them. For this output type definition: Using this map as input: The following struct will be decoded: mapstructure is highly configurable. See the DecoderConfig struct for other features and options that are supported.
- Homepage: https://github.com/mitchellh/mapstructure
- Documentation: https://pkg.go.dev/github.com/mitchellh/mapstructure#section-documentation
- Licenses: MIT
- Latest release: v1.5.0 (published over 2 years ago)
- Last Synced: 2024-11-11T01:04:31.295Z (about 1 month ago)
- Versions: 17
- Dependent Packages: 32,864
- Dependent Repositories: 124,571
- Docker Downloads: 62,915,760,717
-
Rankings:
- Docker downloads count: 0.002%
- Dependent packages count: 0.003%
- Dependent repos count: 0.006%
- Average: 0.39%
- Stargazers count: 0.803%
- Forks count: 1.135%
go: github.com/Mitchellh/mapstructure
- Homepage:
- Documentation: https://pkg.go.dev/github.com/Mitchellh/mapstructure#section-documentation
- Licenses: mit
- Latest release: v1.5.0 (published over 2 years ago)
- Last Synced: 2024-11-11T01:04:24.106Z (about 1 month ago)
- Versions: 17
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 0.77%
- Forks count: 1.113%
- Average: 5.509%
- Dependent packages count: 9.411%
- Dependent repos count: 10.74%
go: github.com/mitchellh/mapStructure
- Homepage:
- Documentation: https://pkg.go.dev/github.com/mitchellh/mapStructure#section-documentation
- Licenses: mit
- Latest release: v1.5.0 (published over 2 years ago)
- Last Synced: 2024-11-11T01:04:27.316Z (about 1 month ago)
- Versions: 17
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.976%
- Average: 7.422%
- Dependent repos count: 7.868%
Dependencies
- actions/checkout v2 composite
- actions/setup-go v2 composite