diff --git a/websocket.go b/websocket.go index 1a00312..ee28295 100644 --- a/websocket.go +++ b/websocket.go @@ -54,8 +54,22 @@ func queueHandler(w http.ResponseWriter, r *http.Request) { continue } + var wdata []byte + switch data := item.Data.(type) { + case string: + wdata = []byte(data) + case []byte: + wdata = data + default: + wdata, err = json.Marshal(data) + if err != nil { + log.Println(err) + continue + } + } + // 写回消息 - err = conn.WriteMessage(websocket.BinaryMessage, []byte(item.Data.(string))) + err = conn.WriteMessage(websocket.BinaryMessage, wdata) if err != nil { log.Println(err) log.Println("重新回队") diff --git a/websocket_test.go b/websocket_test.go index a11c831..c5d7917 100644 --- a/websocket_test.go +++ b/websocket_test.go @@ -37,7 +37,7 @@ func TestWebsocketC(t *testing.T) { fusenrender.StartNode(svc) } -var addr = "localhost:4050" +var addr = "api.fusen.3718.cn:4050" func TestWebsocketCient(t *testing.T) { // u := url.URL{Scheme: "ws", Host: addr, Path: "/ws/pop/queue"}