Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Created September 30, 2014 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jochasinga/f2229382cdef14d01763 to your computer and use it in GitHub Desktop.
Save jochasinga/f2229382cdef14d01763 to your computer and use it in GitHub Desktop.
Embedded Maps in Go
package main
import "fmt"
func main() {
creatures := make(map[string]map[string]string)
creatures = map[string]map[string]string{
"P" : map[string]string{
"name" : "Pokemon",
"power" : "lightning",
"color" : "yellow",
},
"U" : map[string]string{
"name" : "Unicorn",
"power" : "flying",
"color" : "white",
},
"F" : map[string]string{
"name" : "Furby",
"power" : "nagging",
"color" : "various",
},
"G" : map[string]string{
"name" : "Gopher",
"power" : "digging",
"color" : "blue",
},
}
for _, v := range creatures {
fmt.Println(v["name"], "with the power of", v["power"])
}
fmt.Printf("F's name is %s", creatures["F"]["name"])
fmt.Printf("G's color is %s", creatures["G"]["color"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment