-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (39 loc) · 1.05 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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"os"
)
var hangman Hangman
func main() {
fmt.Println("start server")
if len(os.Args) == 1 {
LoadingWord("words.txt")
} else {
LoadingWord(os.Args[1])
}
HangmanInit()
templ := template.Must(template.ParseFiles("./index.html"))
templ2 := template.Must(template.ParseFiles("./hangman.html"))
filescss := http.FileServer(http.Dir("./css"))
http.Handle("/css/", http.StripPrefix("/css/", filescss))
filesimage := http.FileServer(http.Dir("./image"))
http.Handle("/image/", http.StripPrefix("/image/", filesimage))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
templ.Execute(w, nil)
})
http.HandleFunc("/hangman", func(write http.ResponseWriter, respons *http.Request) {
hangman.InputUser = respons.FormValue("user_input")
TryInput(hangman.InputUser)
if respons.Method != http.MethodPost {
HangmanInit()
}
templ2.Execute(write, hangman)
})
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
fmt.Print("close server")
}