/
main.go
99 lines (90 loc) · 2.76 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"net/http"
"io/ioutil"
"log"
)
func logic(word string, input string, used string, mistakes int){
}
func root(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadFile("./layouts/login.html")
if err==nil {
w.Header().Add("Content-Type","text/html")
w.Write(data)
} else {
w.WriteHeader(404)
w.Write([]byte("404 Page not found - "+http.StatusText(404)))
}
}
func gamepage(w http.ResponseWriter, r *http.Request) {
cookie, _ := r.Cookie("Spanzhash")
if(hashExists(cookie.Name))
data, err := ioutil.ReadFile("./layouts/gamepage.html")
if err==nil {
w.Header().Add("Content-Type","text/html")
w.Write(data)
} else {
w.WriteHeader(404)
w.Write([]byte("404 Page not found - "+http.StatusText(404)))
}
}
func dashboard(w http.ResponseWriter, r *http.Request) {
cookie, _ := r.Cookie("Spanzhash")
if(hashExists(cookie.Name))
data, err := ioutil.ReadFile("./layouts/dashboard.html")
if err==nil {
w.Header().Add("Content-Type","text/html")
w.Write(data)
} else {
w.WriteHeader(404)
w.Write([]byte("404 Page not found - "+http.StatusText(404)))
}
}
func register(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadFile("./layouts/register.html")
if err==nil {
w.Header().Add("Content-Type","text/html")
w.Write(data)
} else {
w.WriteHeader(404)
w.Write([]byte("404 Page not found - "+http.StatusText(404)))
}
}
func login(w http.ResponseWriter, r *http.Request) {
email := r.URL.Query().Get("email")
password := r.URL.Query().Get("password")
log.Println(email,password)
if email=="whitehood15@gmail.com" {
w.Write([]byte("id"))
} else {
w.Write([]byte("usrNA"))
}
}
func game(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func insert(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func modify(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
//serve pages
http.HandleFunc("/",root);
http.HandleFunc("/gamepage",gamepage);
http.HandleFunc("/dashboard",dashboard);
http.HandleFunc("/register",register);
//serve Resources
http.Handle("/img/", http.StripPrefix("/img/", http.FileServer(http.Dir("img"))))
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("js"))))
//serve API
http.HandleFunc("/login",login);
http.HandleFunc("/game",game);
http.HandleFunc("/insert",root);
http.HandleFunc("/modify",root);
// start server
http.ListenAndServe(":8080", nil)
}