I have one function in a very small Go application that does a query to a database, retrieves some data and inserts it in the template (main.html). the data is getting inserted into the template (see image), however the html is not being interpreted by the browser (Chrome and Firefox). My browsers are otherwise working fine. Is there something that I'm not doing correct with the template?
func Root(w http.ResponseWriter, r *http.Request) {
t := template.Must(template.New("main").ParseFiles("main.html"))
rows, err := db.Query("SELECT title, author, description FROM books")
PanicIf(err)
defer rows.Close()
books := []Book{}
for rows.Next() {
b := Book{}
err := rows.Scan(&b.Title, &b.Author, &b.Description)
PanicIf(err)
books = append(books, b)
}
t.ExecuteTemplate(w, "main.html", books)
}
main.html
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<table class="table">
<tr>
<th>Title</th>
<th>Author</th>
<th>Description</th>
</tr>
{{ range . }}
<tr>
<td>{{.Title}}</td>
<td>{{.Author}}</td>
<td>{{.Description}}</td>
</tr>
{{ end }}
</table>
</div>
</body>
</html>