How is it possible to close a websocket connection and pass it a message / code?
The docs only define func (ws *Conn) Close() error
without any arguments
I would like to receive the event from JavaScript like this:
websocket.onclose = function(event) {
console.log(event);
};
I am using golang.org/x/net/websocket
Send a close message before closing the connection:
cm := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "add your message here")
if err := c.WriteMessage(websocket.CloseMessage, cm); err != nil {
// handle error
}
c.Close()
It is not possible to specify the close message with the golang.org/x/net/websocket package.