Skip to content

Commit

Permalink
feat: format message type
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool authored and AlexVulaj committed Feb 14, 2024
1 parent 0cfb2ca commit d293aa5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/echo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}()

Expand Down
3 changes: 2 additions & 1 deletion examples/echo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

3 comments on commit d293aa5

@datadius
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this accepted?

messageType is an int with value websocket.BinaryMessage or websocket.TextMessage.

The websocket.FormatMessageType(mt) doesn't event exist in the latest release.

The messageType argument to the WriteMessage and NextWriter methods specifies the type of a sent message.

@reversearrow
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been merged only after the commit was released. @GreenMarmot, are you planning to release a new version?

@RedCrazyGhost
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version of the code doesn't have a FormatMessageType function and shouldn't be in the example, which can be confusing for beginners

Please sign in to comment.