From fb953b665ee752c5e49bca18bb5e7f89290cc568 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Wed, 28 May 2025 14:15:31 +0800 Subject: [PATCH] perf: optimize JSON message construction using `fmt.Appendf` Signed-off-by: Jianhui Zhao --- broker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/broker.go b/broker.go index a7167c4..5ef1765 100644 --- a/broker.go +++ b/broker.go @@ -254,7 +254,7 @@ func (br *broker) run() { case msgTypeFileSend: pipereader, pipewriter := io.Pipe() br.fileProxy.Store(sid, &fileProxy{pipereader, pipewriter}) - s.user.WriteMsg(websocket.TextMessage, []byte(fmt.Sprintf(`{"type":"sendfile", "name": "%s"}`, string(data)))) + s.user.WriteMsg(websocket.TextMessage, fmt.Appendf(nil, `{"type":"sendfile", "name": "%s"}`, string(data))) case msgTypeFileRecv: s.user.WriteMsg(websocket.TextMessage, []byte(`{"type":"recvfile"}`))