Close cleanly closes the underlying WebSocket connection by sending an empty close message and then waiting (with timeout) for the server to close the connection. WebSocket close code may be optionally specified. If not, then "1000 - Normal Closure" will be used. WebSocket close codes are defined
(code ...int)
| 248 | // conn := resp.Connection() |
| 249 | // conn.Close(websocket.CloseUnsupportedData) |
| 250 | func (ws *Websocket) Close(code ...int) *Websocket { |
| 251 | opChain := ws.chain.enter("Close()") |
| 252 | defer opChain.leave() |
| 253 | |
| 254 | switch { |
| 255 | case ws.checkUnusable(opChain, "Close()"): |
| 256 | return ws |
| 257 | |
| 258 | case len(code) > 1: |
| 259 | opChain.fail(AssertionFailure{ |
| 260 | Type: AssertUsage, |
| 261 | Errors: []error{ |
| 262 | errors.New("unexpected multiple code arguments"), |
| 263 | }, |
| 264 | }) |
| 265 | return ws |
| 266 | } |
| 267 | |
| 268 | ws.writeMessage(opChain, websocket.CloseMessage, nil, code...) |
| 269 | |
| 270 | return ws |
| 271 | } |
| 272 | |
| 273 | // CloseWithBytes cleanly closes the underlying WebSocket connection |
| 274 | // by sending given slice of bytes as a close message and then waiting |
nothing calls this directly
no test coverage detected