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

Function ExampleIsUnexpectedCloseError

example_test.go:28–39  ·  example_test.go::ExampleIsUnexpectedCloseError

The websocket.IsUnexpectedCloseError function is useful for identifying application and protocol errors. This server application works with a client application running in the browser. The client application does not explicitly close the websocket. The only expected close message from the client ha

()

Source from the content-addressed store, hash-verified

26// websocket.CloseGoingAway. All other close messages are likely the
27// result of an application or protocol error and are logged to aid debugging.
28func ExampleIsUnexpectedCloseError() {
29 for {
30 messageType, p, err := c.ReadMessage()
31 if err != nil {
32 if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
33 log.Printf("error: %v, user-agent: %v", err, req.Header.Get("User-Agent"))
34 }
35 return
36 }
37 processMessage(messageType, p)
38 }
39}
40
41func processMessage(mt int, p []byte) {}
42

Callers

nothing calls this directly

Calls 4

IsUnexpectedCloseErrorFunction · 0.92
processMessageFunction · 0.85
ReadMessageMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected