This repository was archived by the owner on Jan 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (50 loc) · 1.4 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"html/template"
"log"
"net/http"
"time"
"github.com/golanghr/goer/lib/handlers/gzip"
"github.com/golanghr/goer/lib/handlers/static"
)
const sitePath = "./"
const httpPort = "9000"
var tpls map[string]*template.Template
func init() {
tpls = templateList(sitePath + "templates/")
}
func main() {
regTxtStorage := &RegTxtStorage{Filename: sitePath + "registrations"}
http.Handle("/", &Registration{
Storer: regTxtStorage,
InfoFile: sitePath + "content/event_info.md"})
http.Handle("/resources/", gzip.Handler(static.Handler(sitePath)))
s := &http.Server{
Addr: ":" + httpPort,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
}
log.Println("Server started on port " + httpPort + "...")
log.Print(s.ListenAndServe())
}
func templateList(templateDir string) (templeteList map[string]*template.Template) {
tpls := make(map[string]*template.Template)
driver := template.Must(template.New("master.html").ParseFiles(templateDir + "master.html"))
list := []string{
"registration.html",
}
for _, tplName := range list {
subDriver, err := driver.Clone()
if err != nil {
log.Fatal("cloning template: ", err)
}
_, err = subDriver.ParseFiles(templateDir + tplName)
if err != nil {
log.Fatal("parsing ", tplName, ": ", err)
}
// strip .html sufix
keyName := tplName[:len(tplName)-5]
tpls[keyName] = subDriver
}
return tpls
}