-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (30 loc) · 828 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
package main
import (
"html/template"
"log"
"net/http"
"os"
"strings"
"github.com/partyschaum/go-web-app/controllers"
)
func main() {
templates := populateTemplates()
controllers.Register(templates)
http.ListenAndServe(":8000", nil)
}
func populateTemplates() *template.Template {
result := template.New("templates")
basePath := "templates"
templateFolder, _ := os.Open(basePath)
defer templateFolder.Close()
templatesPathsRaw, _ := templateFolder.Readdir(-1)
templatesPaths := new([]string)
for _, pathInfo := range templatesPathsRaw {
if !pathInfo.IsDir() && strings.HasSuffix(pathInfo.Name(), ".html") {
log.Printf("Loading template %s", pathInfo.Name())
*templatesPaths = append(*templatesPaths, basePath+"/"+pathInfo.Name())
}
}
result.ParseFiles(*templatesPaths...)
return result
}