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