Access a map value using a variable key in a Go template

You use the index function:

{{index .Amap "key1"}}
index
    Returns the result of indexing its first argument by the
    following arguments. Thus "index x 1 2 3" is, in Go syntax,
    x[1][2][3]. Each indexed item must be a map, slice, or array.

https://golang.org/pkg/text/template#hdr-Functions

Leave a Comment