I am trying to use html/template
to parse a JSON in struct format.
func handler(w http.ResponseWriter, r *http.Request) {
var issueList = template.Must(template.New("template01").ParseFiles("template01.tmpl"))
result, err := SearchIssues(os.Args[1:])
if err != nil {
log.Fatal(err)
}
if err := issueList.Execute(w, result); err != nil {
log.Fatal(err)
}
}
The function SearchIssues
is used to convert the stream into JSON format, it works well.
Then I try to parse the JSON by html/template
using
var issueList = template.Must(template.New("template01").ParseFiles("template01.tmpl"))
When I access local services, there is an error : XXX is an incomplete or empty template
.
But when I delete New("template01").
the program runs well.
Like this:
func handler(w http.ResponseWriter, r *http.Request) {
var issueList = template.Must(template.ParseFiles("template01.tmpl"))
result, err := SearchIssues(os.Args[1:])
if err != nil {
log.Fatal(err)
}
if err := issueList.Execute(w, result); err != nil {
log.Fatal(err)
}
}
I am not native speaker, English is not very well, sorry.
{{ Title }}
{{ Paragraph }}
")` or something along those lines – Elias Van Ootegem Oct 05 '22 at 11:38