https://github.com/matryer/m
Get and Set using JavaScript notation
https://github.com/matryer/m
Last synced: 18 days ago
JSON representation
Get and Set using JavaScript notation
- Host: GitHub
- URL: https://github.com/matryer/m
- Owner: matryer
- License: mit
- Created: 2015-01-10T23:56:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-09-02T08:27:35.000Z (over 3 years ago)
- Last Synced: 2025-03-24T15:11:16.586Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 30
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://godoc.org/github.com/matryer/m)
# m
Map utilities for Go### `Get` and `Set` using JavaScript notation
Before (yeah it scrolls):
```
// set the city
data.(map[string]interface{})["addresses"].([]interface{})[0].(map[string]interface{})["city"] = "London"
// get the city
city := data.(map[string]interface{})["addresses"].([]interface{})[0].(map[string]interface{})["city"]
```* Panics if any piece is missing or wrong type
After:
```
m.Set(data, "addresses[0].city", "London")
city := m.Get(data, "addresses[0].city")
```* Returns nil if any piece is missing or wrong type
* Use [`GetOK`](http://godoc.org/github.com/matryer/m#GetOK) for a second argument bool