MCPcopy
hub / github.com/gorilla/websocket / SetCloseHandler

Method SetCloseHandler

conn.go:1135–1144  ·  view source on GitHub ↗

SetCloseHandler sets the handler for close messages received from the peer. The code argument to h is the received close code or CloseNoStatusReceived if the close message is empty. The default close handler sends a close message back to the peer. The handler function is called from the NextReader,

(h func(code int, text string) error)

Source from the content-addressed store, hash-verified

1133// application must perform some action before sending a close message back to
1134// the peer.
1135func (c *Conn) SetCloseHandler(h func(code int, text string) error) {
1136 if h == nil {
1137 h = func(code int, text string) error {
1138 message := FormatCloseMessage(code, "")
1139 c.WriteControl(CloseMessage, message, time.Now().Add(writeWait))
1140 return nil
1141 }
1142 }
1143 c.handleClose = h
1144}
1145
1146// PingHandler returns the current ping handler
1147func (c *Conn) PingHandler() func(appData string) error {

Callers 1

newConnFunction · 0.95

Calls 2

WriteControlMethod · 0.95
FormatCloseMessageFunction · 0.85

Tested by

no test coverage detected