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

Function FormatCloseMessage

conn.go:1227–1238  ·  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

1225// FormatCloseMessage formats closeCode and text as a WebSocket close message.
1226// An empty message is returned for code CloseNoStatusReceived.
1227func FormatCloseMessage(closeCode int, text string) []byte {
1228 if closeCode == CloseNoStatusReceived {
1229 // Return empty message because it's illegal to send
1230 // CloseNoStatusReceived. Return non-nil value in case application
1231 // checks for nil.
1232 return []byte{}
1233 }
1234 buf := make([]byte, 2+len(text))
1235 binary.BigEndian.PutUint16(buf, uint16(closeCode))
1236 copy(buf[2:], text)
1237 return buf
1238}

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