-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathhttp.go
49 lines (43 loc) · 1020 Bytes
/
http.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
package main
import (
"html/template"
"net/http"
)
var (
templates = template.Must(template.ParseGlob("resources/templates/*.html"))
)
type page struct {
Client string
Status string
}
func index(w http.ResponseWriter, r *http.Request) {
c, _ := r.Cookie(Cookie)
http.SetCookie(w, &http.Cookie{
Name: Cookie,
MaxAge: -1,
})
if c != nil {
s := "Installed Dicebot."
if c.Value != Okay {
s = "Error Installing"
}
templates.ExecuteTemplate(w, "index.html", page{
Client: clientID,
Status: s,
})
} else {
templates.ExecuteTemplate(w, "index.html", page{Client: clientID})
}
}
func privacy(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "privacy.html", nil)
}
func main() {
fs := http.FileServer(http.Dir("./resources/assets"))
http.Handle("/assets/", http.StripPrefix("/assets/", fs))
http.HandleFunc("/oauth", Oauth)
http.HandleFunc("/roll", Roll)
http.HandleFunc("/", index)
http.HandleFunc("/privacy", privacy)
http.ListenAndServe(":8080", nil)
}