MCPcopy Create free account
hub / github.com/gorilla/websocket / FormatCloseMessage

Function FormatCloseMessage

conn.go:1219–1230  ·  view source on GitHub ↗

FormatCloseMessage formats closeCode and text as a WebSocket close message. An empty message is returned for code CloseNoStatusReceived.

(closeCode int, text string)

Source from the content-addressed store, hash-verified

1217// FormatCloseMessage formats closeCode and text as a WebSocket close message.
1218// An empty message is returned for code CloseNoStatusReceived.
1219func 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}

Callers 9

pumpStdoutFunction · 0.92
mainFunction · 0.92
echoCopyFunction · 0.92
echoReadAllFunction · 0.92
advanceFrameMethod · 0.85
handleProtocolErrorMethod · 0.85
SetCloseHandlerMethod · 0.85
TestPartialJSONReadFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestPartialJSONReadFunction · 0.68