-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (37 loc) · 978 Bytes
/
main.go
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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
render(w, "test.page.gohtml")
})
fmt.Println("Starting front end service on port 80")
err := http.ListenAndServe(":80", nil)
if err != nil {
log.Panic(err)
}
}
func render(w http.ResponseWriter, t string) {
partials := []string{
"./cmd/web/templates/base.layout.gohtml",
"./cmd/web/templates/header.partial.gohtml",
"./cmd/web/templates/footer.partial.gohtml",
}
var templateSlice []string
templateSlice = append(templateSlice, fmt.Sprintf("./cmd/web/templates/%s", t))
for _, x := range partials {
templateSlice = append(templateSlice, x)
}
tmpl, err := template.ParseFiles(templateSlice...)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tmpl.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}