I am trying to figure out how I can access a map field in a template that contains a space in Go. But I can't seem to figure this out..
I have decoded a JSON array from another source that I don't control like so:
var f []interface{}
json.Unmarshal(externalData, &f)
Then I pass it to ExecuteTemplate as follows:
templates.ExecuteTemplate(w, "templates/data.html", map[string]interface{} { "Data": f })
In my template I use this:
<table>
{{range $element := .Data}}
<tr><td>{{$element.Name}}</td><td>{{$element.**Some Field With Spaces**}}</tr>
{{end}}
</table>
And that is where it goes wrong. I guess I can solve this by renaming the "Some Field With Spaces" key manually before sending the data to the template but I'd like to keep it as is. I figure I could probably also make a template function that returns the right key name but that doesn't seem like a very good solution.