I'm looking for a way of binding json data directly into a template (without any struct representation in golang) - and I'm coming up short. Essentially, what I want is to have both template document and json to be just arbitrary data - and my handleFunc to essentially be:
func handler(writer http.ResponseWriter, request *http.Request) {
t, _ := template.ParseFiles( "someTemplate.html" )
rawJson, _ := ioutil.ReadFile( "someData.json" )
// here's where I need help
somethingTemplateUnderstands := ????( rawJson )
t.Execute( writer, somethingTemplateUnderstands )
}
I've tried json.Unmarshal, but it seems to want a type. The main thing is, in the actual program both the json and the template come from the database and are completely changeable at runtime, (and there are lots of different ones) so I can't encode any structure in the go program itself. And obviously, I want to be able to make data like:
{ "something" : { "a" : "whatever" }}
and then a template like
<html><body>
the value is {{ .something.a }}
</body></html>
Is this possible with the go http.template library, or do I need to go off to Node (or find another templating library?)