-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (53 loc) · 1.53 KB
/
main.go
File metadata and controls
63 lines (53 loc) · 1.53 KB
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
package main
import (
database "RelayServer/database"
routes "RelayServer/routes"
"fmt"
"net/http"
"github.com/gorilla/websocket"
)
var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
}
func handleConnections(w http.ResponseWriter, r *http.Request) {
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
fmt.Println(err)
return
}
defer ws.Close()
for {
_, msg, err := ws.ReadMessage()
if err != nil {
fmt.Println("read error:", err)
break
}
fmt.Printf("Received: %s\n", msg)
if err := ws.WriteMessage(websocket.TextMessage, msg); err != nil {
fmt.Println("write error:", err)
break
}
}
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Let's put something cool here eventually")
}
func main() {
database.InitializeConfig()
database.InitializeDB()
http.HandleFunc("/ws", handleConnections)
http.HandleFunc("/", homeHandler)
routes.RegisterTestEndpoints()
// fmt.Println(database.QueryRow([]string{"id", "username"}, "user", "userID", "user"))
row, _ := database.QueryRow([]string{"id", "username"}, "user", "userID", "usera")
fmt.Println(row)
fmt.Println(len(row))
// fmt.Println(database.Query([]string{"id"}, "serverUser", "serverID", "1"))
fmt.Println("Relay Server active on port 8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
fmt.Println("Relay Exception:", err)
}
// database.queryTableValue("id","user","userID",data[" userID"])
// row := database.QueryRow([]string{"id"}, "user", "userID", "user")
}