message body를 any로 변경

This commit is contained in:
2023-07-11 14:30:10 +09:00
parent 9fd0dd00cb
commit 4acb81a20d
2 changed files with 24 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package wshandler
import (
"context"
"encoding/json"
"github.com/gorilla/websocket"
"repositories.action2quare.com/ayo/gocommon/logger"
@ -54,8 +55,6 @@ func (r *room) loop(ctx context.Context, conns *map[string]*wsconn) (normalEnd b
}
}()
a, b, c := []byte(`{"alias":"`), []byte(`","body":"`), []byte(`"}`)
for {
select {
case <-ctx.Done():
@ -68,13 +67,16 @@ func (r *room) loop(ctx context.Context, conns *map[string]*wsconn) (normalEnd b
delete((*conns), conn.sender.Accid.Hex())
case msg := <-r.messageChan:
ds := DownstreamMessage{
Alias: msg.Alias,
Body: msg.Body,
Tag: append(msg.Tag, r.name),
}
bt, _ := json.Marshal(ds)
for _, conn := range *conns {
writer, _ := conn.NextWriter(websocket.TextMessage)
writer.Write(a)
writer.Write([]byte(msg.Alias))
writer.Write(b)
writer.Write(msg.Body)
writer.Write(c)
writer.Write(bt)
writer.Close()
}
}