JSON Template as template language in Go programming language

127 views
Skip to first unread message

Andy Chu

unread,
Nov 14, 2009, 1:23:26 PM11/14/09
to JSON Template
You may have seen that some of my well known coworkers released the Go
programming language:

http://golang.org/doc/effective_go.html#web_server

The syntax of the templating language is basically a subset of JSON
Template. However there is no JSON involved -- it uses reflection on
Go structs.

"The template package, inspired by json-template, is powerful; this
program just touches on its capabilities. In essence, it rewrites a
piece of text on the fly by substituting elements derived from data
items passed to templ.Execute, in this case the form value. Within the
template text (templateStr), brace-delimited pieces denote template
actions. The piece from the {.section @} to {.end} executes with the
value of the data item @, which is a shorthand for “the current item”,
which is the form value. (When the string is empty, this piece of the
template is suppressed.) "

Eventually I want to make this JSON/struct difference moot. JSON
Template is a data-driven templating language. There is the analogy:

JS object (in memory) : JSON Serialization format

::

Struct (in memory) :: Protocol Buffer (Google serialization format)

JSON Template can work with the first 2 things. Since protocol
buffers are in some way "isomorphic" to JSON -- they are both a tree
of key-value pairs, JSON Template should be able to work with the
latter two as well. (Although the name might be out of date at that
point...)

Andy

Reply all
Reply to author
Forward
0 new messages