feat: format message type

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
This commit is contained in:
rfyiamcool 2024-01-23 15:02:44 +08:00 committed by Alex Vulaj
parent 0cfb2cafd0
commit d293aa53e1
2 changed files with 4 additions and 3 deletions

View File

@ -41,12 +41,12 @@ func main() {
go func() {
defer close(done)
for {
_, message, err := c.ReadMessage()
mt, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
log.Printf("recv: %s", message)
log.Printf("recv: %s, type: %s", message, websocket.FormatMessageType(mt))
}
}()

View File

@ -33,7 +33,8 @@ func echo(w http.ResponseWriter, r *http.Request) {
log.Println("read:", err)
break
}
log.Printf("recv: %s", message)
log.Printf("recv: %s, type: %s", message, websocket.FormatMessageType(mt))
err = c.WriteMessage(mt, message)
if err != nil {
log.Println("write:", err)