-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (36 loc) · 890 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
43
44
45
/*
* Mumbo - A fast in-memory key value store
* Copyright(c) 2016-present @GavinDmello
* BSD Licensed
*/
package main
import (
"net/http"
"fmt"
"github.com/gorilla/websocket"
)
var upgrader = websocket.Upgrader{}
// where all the magic begins
func main() {
// read the config
readConfig()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
var conn, _ = upgrader.Upgrade(w, r, nil)
go handleConnection(conn)
})
fmt.Println("Server started on port", port)
http.ListenAndServe(port, nil)
}
// handles the client connections
func handleConnection(conn *websocket.Conn) {
var msg interface{}
for {
err := conn.ReadJSON(&msg)
if err != nil {
conn.Close()
break
}
result := check(msg.(map[string]interface{}))
conn.WriteJSON(result)
}
}