-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
39 lines (32 loc) · 922 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
package editor
import (
"log"
"net/http"
"github.com/google/uuid"
"github.com/gorilla/websocket"
)
// This file just defines some of the endpoints for the editor
// and ties together its various disparate components
var Upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
// Actual edit endpoint
func EditEndpoint(w http.ResponseWriter, r *http.Request) {
requestedDocument, ok := r.URL.Query()["document"]
if !ok || len(requestedDocument[0]) < 1 {
w.WriteHeader(400)
return
}
ws, err := Upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
}
wsClient := newClient(ws)
targetServer := GetDocumentServerFactoryInstance().FetchDocumentServer(uuid.MustParse(requestedDocument[0]))
commPipe, signalDeparturePipe := targetServer.connectClient(wsClient)
go wsClient.run(commPipe, signalDeparturePipe)
}