Buffer template output
This commit is contained in:
parent
a2d09d8e68
commit
87cae430a3
@ -1,8 +1,10 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -29,12 +31,14 @@ func (t Template) Execute(w http.ResponseWriter, r *http.Request, data interface
|
||||
})
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||
err = tpl.Execute(w, data)
|
||||
var buf bytes.Buffer
|
||||
err = tpl.Execute(&buf, data)
|
||||
if err != nil {
|
||||
log.Printf("Error executing template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
io.Copy(w, &buf)
|
||||
}
|
||||
func (t Template) TestTemplate(data interface{}) error {
|
||||
var testWriter strings.Builder
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user