Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: format message type #889

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

rfyiamcool
Copy link
Contributor

summary

The messageType and message can be retrieved using the readMessage method, i want to convert mt int to string by FormatMessageType ? 😁

var upgrader = websocket.Upgrader{} // use default options

func echo(w http.ResponseWriter, r *http.Request) {
	c, err := upgrader.Upgrade(w, r, nil)
	if err != nil {
		log.Print("upgrade:", err)
		return
	}
	defer c.Close()
	for {
		mt, message, err := c.ReadMessage()
		if err != nil {
			log.Println("read:", err)
			break
		}

		log.Printf("recv: %s, type: %s", message, websocket.FormatMessageType(mt))  // 😁

		err = c.WriteMessage(mt, message)
		if err != nil {
			log.Println("write:", err)
			break
		}
	}
}

@AlexVulaj
Copy link
Member

Nice addition @rfyiamcool , thanks! Looks good to me.

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3168614) 71.26% compared to head (95fef26) 71.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #889      +/-   ##
==========================================
+ Coverage   71.26%   71.30%   +0.03%     
==========================================
  Files          11       11              
  Lines        1587     1589       +2     
==========================================
+ Hits         1131     1133       +2     
  Misses        349      349              
  Partials      107      107              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
@AlexVulaj AlexVulaj force-pushed the feat/format_message_type branch from 181effb to 95fef26 Compare February 14, 2024 03:58
@AlexVulaj AlexVulaj merged commit d293aa5 into gorilla:main Feb 14, 2024
8 of 12 checks passed
algitbot pushed a commit to alpinelinux/build-server-status that referenced this pull request Sep 15, 2024
This MR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/gorilla/websocket](https://github.com/gorilla/websocket) | require | patch | `v1.5.1` -> `v1.5.3` |

---

### Release Notes

<details>
<summary>gorilla/websocket (github.com/gorilla/websocket)</summary>

### [`v1.5.3`](https://github.com/gorilla/websocket/releases/tag/v1.5.3)

[Compare Source](gorilla/websocket@v1.5.2...v1.5.3)

#### Important change

This reverts the websockets package back to gorilla/websocket@931041c

#### What's Changed

-   Fixes subprotocol selection (aling with rfc6455) by [@&#8203;KSDaemon](https://github.com/KSDaemon) in gorilla/websocket#823
-   Update README.md, replace master to main by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#862
-   Use status code constant by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#864
-   conn.go: default close handler should not return ErrCloseSent. by [@&#8203;pnx](https://github.com/pnx) in gorilla/websocket#865
-   fix: replace ioutil.readfile with os.readfile by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#868
-   fix: add comment for the readBufferSize and writeBufferSize by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#869
-   Remove noisy printf in NextReader() and beginMessage() by [@&#8203;bcreane](https://github.com/bcreane) in gorilla/websocket#878
-   docs(echoreadall): fix function echoReadAll comment by [@&#8203;XdpCs](https://github.com/XdpCs) in gorilla/websocket#881
-   make tests parallel by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#872
-   Upgrader.Upgrade: use http.ResposnseController by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#871
-   Do not handle network error in `SetCloseHandler()` by [@&#8203;nak3](https://github.com/nak3) in gorilla/websocket#863
-   perf: reduce timer in write_control by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#879
-   fix: lint example code by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#890
-   feat: format message type by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#889
-   Remove hideTempErr to allow downstream users to check for errors like net.ErrClosed by [@&#8203;UnAfraid](https://github.com/UnAfraid) in gorilla/websocket#894
-   Do not timeout when WriteControl deadline is zero in gorilla/websocket#898
-   Excludes errchecks linter by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#904
-   Return errors instead of printing to logs by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#897
-   Revert " Update go version & add verification/testing tools ([#&#8203;840](gorilla/websocket#840))" by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#908
-   Fixes broken random value generation by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#926
-   Reverts back to v1.5.0 by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#929

#### New Contributors

-   [@&#8203;KSDaemon](https://github.com/KSDaemon) made their first contribution in gorilla/websocket#823
-   [@&#8203;mstmdev](https://github.com/mstmdev) made their first contribution in gorilla/websocket#862
-   [@&#8203;pnx](https://github.com/pnx) made their first contribution in gorilla/websocket#865
-   [@&#8203;rfyiamcool](https://github.com/rfyiamcool) made their first contribution in gorilla/websocket#868
-   [@&#8203;bcreane](https://github.com/bcreane) made their first contribution in gorilla/websocket#878
-   [@&#8203;XdpCs](https://github.com/XdpCs) made their first contribution in gorilla/websocket#881
-   [@&#8203;ninedraft](https://github.com/ninedraft) made their first contribution in gorilla/websocket#872
-   [@&#8203;nak3](https://github.com/nak3) made their first contribution in gorilla/websocket#863
-   [@&#8203;UnAfraid](https://github.com/UnAfraid) made their first contribution in gorilla/websocket#894
-   [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) made their first contribution in gorilla/websocket#904

**Full Changelog**: gorilla/websocket@v1.5.1...v1.5.3

### [`v1.5.2`](https://github.com/gorilla/websocket/releases/tag/v1.5.2)

[Compare Source](gorilla/websocket@v1.5.1...v1.5.2)

#### What's Changed

-   Fixes subprotocol selection (aling with rfc6455) by [@&#8203;KSDaemon](https://github.com/KSDaemon) in gorilla/websocket#823
-   Update README.md, replace master to main by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#862
-   Use status code constant by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#864
-   conn.go: default close handler should not return ErrCloseSent. by [@&#8203;pnx](https://github.com/pnx) in gorilla/websocket#865
-   fix: replace ioutil.readfile with os.readfile by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#868
-   fix: add comment for the readBufferSize and writeBufferSize by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#869
-   Remove noisy printf in NextReader() and beginMessage() by [@&#8203;bcreane](https://github.com/bcreane) in gorilla/websocket#878
-   docs(echoreadall): fix function echoReadAll comment by [@&#8203;XdpCs](https://github.com/XdpCs) in gorilla/websocket#881
-   make tests parallel by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#872
-   Upgrader.Upgrade: use http.ResposnseController by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#871
-   Do not handle network error in `SetCloseHandler()` by [@&#8203;nak3](https://github.com/nak3) in gorilla/websocket#863
-   perf: reduce timer in write_control by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#879
-   fix: lint example code by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#890
-   feat: format message type by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#889
-   Remove hideTempErr to allow downstream users to check for errors like net.ErrClosed by [@&#8203;UnAfraid](https://github.com/UnAfraid) in gorilla/websocket#894
-   Do not timeout when WriteControl deadline is zero in gorilla/websocket#898
-   Excludes errchecks linter by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#904
-   Return errors instead of printing to logs by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#897
-   Revert " Update go version & add verification/testing tools ([#&#8203;840](gorilla/websocket#840))" by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#908
-   Fixes broken random value generation by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#926

#### New Contributors

-   [@&#8203;KSDaemon](https://github.com/KSDaemon) made their first contribution in gorilla/websocket#823
-   [@&#8203;mstmdev](https://github.com/mstmdev) made their first contribution in gorilla/websocket#862
-   [@&#8203;pnx](https://github.com/pnx) made their first contribution in gorilla/websocket#865
-   [@&#8203;rfyiamcool](https://github.com/rfyiamcool) made their first contribution in gorilla/websocket#868
-   [@&#8203;bcreane](https://github.com/bcreane) made their first contribution in gorilla/websocket#878
-   [@&#8203;XdpCs](https://github.com/XdpCs) made their first contribution in gorilla/websocket#881
-   [@&#8203;ninedraft](https://github.com/ninedraft) made their first contribution in gorilla/websocket#872
-   [@&#8203;nak3](https://github.com/nak3) made their first contribution in gorilla/websocket#863
-   [@&#8203;UnAfraid](https://github.com/UnAfraid) made their first contribution in gorilla/websocket#894
-   [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) made their first contribution in gorilla/websocket#904

**Full Changelog**: gorilla/websocket@v1.5.1...v1.5.2

</details>

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

&nbsp;
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yODYuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQxOS4xIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->

See merge request alpine/infra/build-server-status!14
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants