I'm fetching data from postgresql using this:
type Todo struct {
ID int
Body string
AuthorID int
Done bool
}
err := rows.Scan(&todo.ID, &todo.Body, &todo.AuthorID, &todo.Done)
I return this from the function, is a slice of *Todo structs.
In the handler, the output of for
_, todo := range todos {
fmt.Fprintf(w, "%d, %s, %d, %t
", todo.ID, todo.Body, todo.AuthorID, todo.Done)
}
is:
2018/10/03 20:09:00 &{1 buy carrots 123 true}
2018/10/03 20:09:00 &{2 cook carrots 123 false}
2018/10/03 20:09:00 &{3 eat carrots 125 false}
the output of
fmt.Printf("%#v", todos)
is:
[]*models.Todo{}
When I pass this as data to template.execute,
<body>
{{ range . }}
<div>
<div>
<strong>{{ .AuthorID }} wrote:</strong>
</div>
<div>{{ .Body }}</div>
</div>
{{ end }}
</body>
Displays nothing.
I am really puzzled here, there are no errors anywhere, and googling brings me nothing.
I simply forgot to append the new todo insantiation to the todos slice
Sigh, three hours of my life