Buffer template output
This commit is contained in:
parent
a2d09d8e68
commit
87cae430a3
@ -1,8 +1,10 @@
|
|||||||
package views
|
package views
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"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")
|
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 {
|
if err != nil {
|
||||||
log.Printf("Error executing template: %v", err)
|
log.Printf("Error executing template: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
io.Copy(w, &buf)
|
||||||
}
|
}
|
||||||
func (t Template) TestTemplate(data interface{}) error {
|
func (t Template) TestTemplate(data interface{}) error {
|
||||||
var testWriter strings.Builder
|
var testWriter strings.Builder
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user