func WsHandle(writer http.ResponseWriter, request *http.Request) {
var (
conn *websocket.Conn
err error
messageType int
data []byte
)
if conn, err = upgrader.Upgrade(writer, request, nil); err != nil {
goto ERR
}
for {
fmt.Printf("connection: %v", conn)
if messageType, data, err = conn.ReadMessage(); err != nil {
goto ERR
}
switch messageType {
case websocket.TextMessage:
fmt.Println(string(data))
if err = conn.WriteMessage(websocket.TextMessage, data); err != nil {
goto ERR
}
break
case websocket.BinaryMessage:
break
}
}
ERR:
conn.Close()
}