This repository has been archived by the owner on Sep 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
65 lines (55 loc) · 1.61 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
// Licensed under GPL, 2016
// Refer to LICENSE for more details
// Refer to README for structural information
package main
import (
"github.com/dchest/captcha"
"html/template"
"log"
"net/http"
"strk.kbt.io/projects/go/libravatar"
)
const (
diff = "d"
new = "n"
pop = "p"
)
type errorPage struct {
H, M string // header and message
}
var t *template.Template
func main() {
t = template.Must(template.New("redb").Funcs(template.FuncMap{
"libr": func(author string) string {
r, _ := libravatar.FromEmail(author)
return r
},
}).ParseGlob("html/*.gtml"))
// close database connection before quitting
defer db.Close()
// start ReGeX game server in parallel
go gameServer()
// handle HTTP requests
http.HandleFunc("/", index(new, true))
http.HandleFunc("/new", index(new, false))
http.HandleFunc("/pop", index(pop, false))
http.HandleFunc("/diff", index(diff, false))
http.HandleFunc("/r/", showRegex)
http.HandleFunc("/contrib", contrib)
http.HandleFunc("/search", search)
http.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) {
t.ExecuteTemplate(w, "about.gtml", nil)
})
http.HandleFunc("/style.css", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./css/style.css")
})
http.HandleFunc("/logo.png", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./img/logo.png")
})
http.HandleFunc("/flavicon.png", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./img/flavicon.png")
})
http.Handle("/c/", captcha.Server(260, 80))
log.Println("Starting server on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}