Skip to content

dahernan/m

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc

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 for a second argument bool

About

Get and Set using JavaScript notation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%