From f3de061423a0dbcf042569792fe9f036d30c877d Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 16 Aug 2023 13:13:45 +0800 Subject: [PATCH] fix --- websocket.go | 16 +++++++++++++++- websocket_test.go | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) 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"}