perf: optimize JSON message construction using fmt.Appendf

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2025-05-28 14:15:31 +08:00
parent bb112787d0
commit fb953b665e
+1 -1
View File
@@ -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"}`))