|
|
@ -5,6 +5,7 @@ import (
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -12,12 +13,16 @@ import (
|
|
|
|
var upgrader = websocket.Upgrader{
|
|
|
|
var upgrader = websocket.Upgrader{
|
|
|
|
ReadBufferSize: 1024,
|
|
|
|
ReadBufferSize: 1024,
|
|
|
|
WriteBufferSize: 1024,
|
|
|
|
WriteBufferSize: 1024,
|
|
|
|
|
|
|
|
CheckOrigin: func(r *http.Request) bool {
|
|
|
|
|
|
|
|
return strings.Contains(r.Host, "localhost")
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newConnection(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func newConnection(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ws, err := upgrader.Upgrade(w, r, nil)
|
|
|
|
ws, err := upgrader.Upgrade(w, r, nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprint(w, "You must use the websocket protocol to connect to this endpoint.", err)
|
|
|
|
fmt.Fprintf(w, "An error has occured: %s.\n", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer ws.Close()
|
|
|
|
defer ws.Close()
|
|
|
|
|
|
|
|
|
|
|
|