This commit is contained in:
Henrique Dias
2016-06-22 21:03:48 +01:00
parent 68aea511fa
commit 6bc5b881d6
6 changed files with 304 additions and 296 deletions

14
page.go
View File

@@ -1,8 +1,6 @@
package filemanager
import (
"bufio"
"bytes"
"encoding/json"
"html/template"
"log"
@@ -102,16 +100,18 @@ func (p *Page) AddTemplate(name string, assets AssetFunc, functions template.Fun
// PrintAsHTML formats the page in HTML and executes the template
func (p Page) PrintAsHTML(w http.ResponseWriter) (int, error) {
var buffer bytes.Buffer
writer := bufio.NewWriter(&buffer)
err := p.Tpl.Execute(writer, p.Info)
// var buffer bytes.Buffer
//writer := bufio.NewWriter(&buffer)
err := p.Tpl.Execute(w, p.Info)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err != nil {
return http.StatusInternalServerError, err
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
buffer.WriteTo(w)
// _, err = buffer.WriteTo(w)
// w.Write(buffer.Bytes())
return http.StatusOK, nil
}