mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
better error check
This commit is contained in:
parent
e224512908
commit
68aea511fa
9
page.go
9
page.go
@ -1,6 +1,8 @@
|
|||||||
package filemanager
|
package filemanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
@ -100,13 +102,16 @@ func (p *Page) AddTemplate(name string, assets AssetFunc, functions template.Fun
|
|||||||
|
|
||||||
// PrintAsHTML formats the page in HTML and executes the template
|
// PrintAsHTML formats the page in HTML and executes the template
|
||||||
func (p Page) PrintAsHTML(w http.ResponseWriter) (int, error) {
|
func (p Page) PrintAsHTML(w http.ResponseWriter) (int, error) {
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
var buffer bytes.Buffer
|
||||||
err := p.Tpl.Execute(w, p.Info)
|
writer := bufio.NewWriter(&buffer)
|
||||||
|
err := p.Tpl.Execute(writer, p.Info)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
buffer.WriteTo(w)
|
||||||
return http.StatusOK, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user