-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (34 loc) · 871 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"golang-webchat/server"
"log"
"net/http"
)
func main() {
server.AllRooms.Init()
http.HandleFunc("/create", server.CreateRoomRequestHandler)
http.HandleFunc("/join", server.JoinRoomRequestHandler)
http.HandleFunc("/checkroom", func(w http.ResponseWriter, r *http.Request) {
roomID, ok := r.URL.Query()["roomID"]
if !ok {
log.Println("roomID is missing when want to check room")
json.NewEncoder(w).Encode(struct {
Message string `json:"message"`
}{Message: "roomID is missing when want to check room"})
return
}
if _, ok := server.AllRooms.Map[roomID[0]]; !ok {
fmt.Fprint(w, "not found")
return
}
fmt.Fprint(w, "found")
return
})
log.Println("Starting Server on Port 8000")
err := http.ListenAndServe(":8000", nil)
if err != nil {
log.Fatal("FATAL ERROR : ", err)
}
}