How to parseFile with ...string?

46 views
Skip to first unread message

Vivi

unread,
May 20, 2020, 12:40:38 PM5/20/20
to golang-nuts
I have not thought of a way how to have 2 or multiple files as a separate string to be parsed by API that request for ...string
The end goal to verify HTML template for error through a function call, is there a better approach?

func checkHTML(str string) {
       
template.ParseFiles(strHTML)
}

Saied Seghatoleslami

unread,
May 20, 2020, 12:56:44 PM5/20/20
to golang-nuts
This is what Alex Edwards in his book "Let's Go" does and I am using it.  He writes it to a buffer and checks for errors.

Enter code here...

Enter code here...func (app *App) render(w http.ResponseWriter, r *http.Request, name string) {
t := app.cache[name]
buf := new(bytes.Buffer)
tData, err := app.addDefaultData(app.td, r)
if err != nil {
app.serverError(w, err)
}
err = t.Execute(buf, tData)
if err != nil {
app.serverError(w, err)
return
}
buf.WriteTo(w)
}
Reply all
Reply to author
Forward
0 new messages