Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.