Skip to content

Instantly share code, notes, and snippets.

@FilBot3
Last active September 23, 2016 02:09
Show Gist options
  • Select an option

  • Save FilBot3/32bb95a51d6b980db1866d5e2bea9e4b to your computer and use it in GitHub Desktop.

Select an option

Save FilBot3/32bb95a51d6b980db1866d5e2bea9e4b to your computer and use it in GitHub Desktop.
Nested Maps in Slices with GO.
package main
import "fmt"
func main() {
// Initalize a Slice that holds Maps of strings
slice_1 := make([]map[string]string, 0)
// Initialize a Map of string keys and string values
map_1 := make(map[string]string)
// Assign a Key, key, and a value, farts
map_1["key"] = "farts"
map_1["stuff"] = "more"
map_2 := make(map[string]string)
map_2["key"] = "things"
// Assign slice_1 to take the return of append, appending map_1 to slice_1
slice_1 = append(slice_1, map_1)
slice_1 = append(slice_1, map_2)
fmt.Println(slice_1)
// Access the value of the Hash map
fmt.Println(slice_1[0]["key"])
}
$ go run nested_slices.go
[map[key:farts stuff:more] map[key:things]]
farts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment