mirror of https://github.com/gorilla/websocket.git
feat: format message type
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
This commit is contained in:
parent
316861440d
commit
0cfb2cafd0
12
conn.go
12
conn.go
|
@ -1263,3 +1263,15 @@ func FormatCloseMessage(closeCode int, text string) []byte {
|
||||||
copy(buf[2:], text)
|
copy(buf[2:], text)
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var messageTypes = map[int]string{
|
||||||
|
TextMessage: "TextMessage",
|
||||||
|
BinaryMessage: "BinaryMessage",
|
||||||
|
CloseMessage: "CloseMessage",
|
||||||
|
PingMessage: "PingMessage",
|
||||||
|
PongMessage: "PongMessage",
|
||||||
|
}
|
||||||
|
|
||||||
|
func FormatMessageType(mt int) string {
|
||||||
|
return messageTypes[mt]
|
||||||
|
}
|
||||||
|
|
17
conn_test.go
17
conn_test.go
|
@ -797,3 +797,20 @@ func TestFailedConnectionReadPanic(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Fatal("should not get here")
|
t.Fatal("should not get here")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFormatMessageType(t *testing.T) {
|
||||||
|
str := FormatMessageType(TextMessage)
|
||||||
|
if str != messageTypes[TextMessage] {
|
||||||
|
t.Error("failed to format message type")
|
||||||
|
}
|
||||||
|
|
||||||
|
str = FormatMessageType(CloseMessage)
|
||||||
|
if str != messageTypes[CloseMessage] {
|
||||||
|
t.Error("failed to format message type")
|
||||||
|
}
|
||||||
|
|
||||||
|
str = FormatMessageType(123)
|
||||||
|
if str != messageTypes[123] {
|
||||||
|
t.Error("failed to format message type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue