]> Cypherpunks repositories - gostls13.git/commit
exp/template: support field syntax on maps
authorGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 15 Aug 2011 03:56:01 +0000 (00:56 -0300)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 15 Aug 2011 03:56:01 +0000 (00:56 -0300)
commite3df71f50bfd7e2d0706a6fa8d3ff56b3d7c4b0a
tree71118da60a5cd182af30d3c2f1ab081db2b8efb0
parente3f3a5411a3f60d8ab52fb335ee4eff6eb531fd9
exp/template: support field syntax on maps

While using exp/template in practice, the syntax for
indexing values using the "index" action was found to be
very inconvenient for frequent use when handling dynamic
data from maps such as the ones used with json and yaml,
that use a type like map[string]interface{}.

For these kinds of maps, the default handling of fields as
{{.Field}} makes the task of handling the several references
significantly more pleasant and elegant, and is equivalent
to what's currently done in the "template" package and in
other external packages (e.g. mustache).

Even with this change, the index action is still relevant
as it allows indexing maps in other scenarios where keys
wouldn't be valid field names.

R=golang-dev, r, gustavo
CC=golang-dev
https://golang.org/cl/4898043
src/pkg/exp/template/doc.go
src/pkg/exp/template/exec.go
src/pkg/exp/template/exec_test.go