From 95fef2623801b90f10672630c9315a62cca5d450 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Tue, 23 Jan 2024 15:02:44 +0800 Subject: [PATCH] feat: format message type Signed-off-by: rfyiamcool --- examples/echo/client.go | 4 ++-- examples/echo/server.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/echo/client.go b/examples/echo/client.go index 7d870bdf..d53b81c8 100644 --- a/examples/echo/client.go +++ b/examples/echo/client.go @@ -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)) } }() diff --git a/examples/echo/server.go b/examples/echo/server.go index f9a0b7b5..9804e6b2 100644 --- a/examples/echo/server.go +++ b/examples/echo/server.go @@ -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)