-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.go
More file actions
47 lines (39 loc) · 947 Bytes
/
templates.go
File metadata and controls
47 lines (39 loc) · 947 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package server
import (
"html/template"
"net/http"
)
type templateSet struct {
index *template.Template
email *template.Template
block *template.Template
}
func newTemplateSet() (templateSet, error) {
indexTemplate, err := parsePageTemplate("templates/index.html.tmpl")
if err != nil {
return templateSet{}, err
}
emailTemplate, err := parsePageTemplate("templates/email.html.tmpl")
if err != nil {
return templateSet{}, err
}
blockTemplate, err := parsePageTemplate("templates/block.html.tmpl")
if err != nil {
return templateSet{}, err
}
return templateSet{
index: indexTemplate,
email: emailTemplate,
block: blockTemplate,
}, nil
}
func parsePageTemplate(pageFile string) (*template.Template, error) {
return template.ParseFS(
templatesFS,
"templates/layout.html.tmpl",
pageFile,
)
}
func setHTMLHeader(writer http.ResponseWriter) {
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
}