Skip to content
New issue

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

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

Already on GitHub? Sign in 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.

@AlexVulaj AlexVulaj merged commit d293aa5 into gorilla:main Feb 14, 2024
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants