|
@@ -27,6 +27,7 @@ var (
|
|
|
indexTemplate = template.Must(template.ParseFiles("www\\index.html"))
|
|
|
logInTemplate = template.Must(template.ParseFiles("www\\login.html"))
|
|
|
signInTemplate = template.Must(template.ParseFiles("www\\signin.html"))
|
|
|
+ gameTemplate = template.Must(template.ParseFiles("www\\game.html"))
|
|
|
)
|
|
|
|
|
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|
@@ -181,6 +182,21 @@ func signInPostHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
signInTemplate.Execute(w, data)
|
|
|
}
|
|
|
|
|
|
+func gameGetHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
+ gameTemplate.Execute(w, nil)
|
|
|
+}
|
|
|
+
|
|
|
+func gamePostHandler(w http.ResponseWriter, r *http.Request){ //TODO запись score в таблицу
|
|
|
+ if err := r.ParseForm(); err != nil {
|
|
|
+ fmt.Fprintf(w, "ParseForm() err: %v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Printf("Post from website! r.PostFrom = %v\n", r.PostForm)
|
|
|
+ score := r.FormValue("score")
|
|
|
+ fmt.Fprintf(w,"score = %s\n", score)
|
|
|
+ fmt.Printf("score = %s\n", score)
|
|
|
+}
|
|
|
+
|
|
|
func createLogger() {
|
|
|
startTime := time.Now()
|
|
|
logFileName := "logs/go-site_log_" + startTime.Format("2006-01-02_15-04-05") + ".txt"
|
|
@@ -215,12 +231,14 @@ func main() {
|
|
|
|
|
|
|
|
|
requestRouter.HandleFunc("/", indexHandler).Methods("GET")
|
|
|
- requestRouter.HandleFunc("/", indexPostHandler).Methods("POST") //Есть ли нужда в обработке POST для /
|
|
|
+ //requestRouter.HandleFunc("/", indexPostHandler).Methods("POST") //Есть ли нужда в обработке POST для /
|
|
|
requestRouter.HandleFunc("/login/", logInGetHandler).Methods("GET")
|
|
|
requestRouter.HandleFunc("/login/", logInPostHandler).Methods("POST")
|
|
|
requestRouter.HandleFunc("/logout/", logOutGetHandler).Methods("GET")
|
|
|
requestRouter.HandleFunc("/signin/", signInGetHandler).Methods("GET")
|
|
|
requestRouter.HandleFunc("/signin/", signInPostHandler).Methods("POST")
|
|
|
+ requestRouter.HandleFunc("/game/", gameGetHandler).Methods("GET")
|
|
|
+ requestRouter.HandleFunc("/", gamePostHandler).Methods("POST")
|
|
|
http.Handle("/", requestRouter)
|
|
|
logger.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
}
|