FormatCloseMessage formats closeCode and text as a WebSocket close message. An empty message is returned for code CloseNoStatusReceived.
(closeCode int, text string)
| 1225 | // FormatCloseMessage formats closeCode and text as a WebSocket close message. |
| 1226 | // An empty message is returned for code CloseNoStatusReceived. |
| 1227 | func FormatCloseMessage(closeCode int, text string) []byte { |
| 1228 | if closeCode == CloseNoStatusReceived { |
| 1229 | // Return empty message because it's illegal to send |
| 1230 | // CloseNoStatusReceived. Return non-nil value in case application |
| 1231 | // checks for nil. |
| 1232 | return []byte{} |
| 1233 | } |
| 1234 | buf := make([]byte, 2+len(text)) |
| 1235 | binary.BigEndian.PutUint16(buf, uint16(closeCode)) |
| 1236 | copy(buf[2:], text) |
| 1237 | return buf |
| 1238 | } |
no outgoing calls