Following is the snippet of a working code. I am using gin templating engine.
c.HTML(200, "index", gin.H{
"title": "Welcome",
"students": map[int]map[string]string{1: {"PID": "1", "Name": "myName"}},})
And in index template I have:
<TABLE class= "myTable" >
<tr class="headingTr">
<td>Name</td>
</tr>
{{range $student := .students}}
<td>{{$student.Name}}</td>
{{end}}
</TABLE>
As you can see I have hard-coded the value of students
on the headers (the map). I want to have this data from a rest API that I have built. the response of my rest API is an array:
[
{
"id": 1,
"name": "Mary"
},
{
"id": 2,
"name": "John"
}
]
I can unmarshal this JSON response into map[string]string
instead of map[int]map[string]string
. How can pass this unmarhsaled body in parameter value for students and then iterate over this array the index template?