-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
executable file
·64 lines (57 loc) · 1.56 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
package main
import (
"io"
"log"
"net/http"
"strings"
)
const StackVersion = "v0.3"
func serveTemplate(res http.ResponseWriter, name string, data interface{}) {
contents, err := compileTemplate(name, data)
if err != nil {
http.Error(res, err.Error(), 500)
return
}
res.Header().Set("Content-Type", "text/html")
io.WriteString(res, contents)
}
func assetURL(name string) string {
return "/assets/" + name
}
func init() {
log.SetFlags(0)
// HTTP
http.HandleFunc("/stack", func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/html")
serveTemplate(res, "stack/index", map[string]string{
"StackVersion": StackVersion,
})
})
http.HandleFunc("/license", func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/html")
serveTemplate(res, "license", nil)
})
http.HandleFunc("/rbsa", func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/html")
serveTemplate(res, "rbsa/index", nil)
})
http.HandleFunc("/socketmaster", func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/html")
serveTemplate(res, "socketmaster/index", nil)
})
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
if req.URL.Path == "/" || strings.ToLower(req.URL.Path) == "/index.htm" {
res.Header().Set("Content-Type", "text/html")
serveTemplate(res, "index", nil)
} else {
http.Error(res, "Page Not Found", 404)
}
})
}
func main() {
log.SetFlags(0)
err := build()
if err != nil {
log.Fatalln(err)
}
}