blob: 00a8eb2e18187728960c7c7e4f115c9713b220c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package utils
import (
"log"
"net/http"
"io/ioutil"
"text/template" // FIXME switch to html/template for security reasons
// and make a workaround for rendered Markdown insertion
)
func ServeTemplate(w http.ResponseWriter, name string, path string, data interface{}) {
templateFile,err := ioutil.ReadFile(path)
if err != nil {
log.Print(err)
http.Error(w, http.StatusText(404), 404)
return
}
tmpl,err := template.New(name).Parse(string(templateFile))
if err != nil {
log.Print(err)
http.Error(w, http.StatusText(404), 404)
return
}
err = tmpl.Execute(w, data)
if err != nil {
log.Print(err)
http.Error(w, http.StatusText(404), 404)
return
}
}
|