MCPcopy
hub / github.com/coder/websocket / ExampleCloseStatus

Function ExampleCloseStatus

example_test.go:63–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61}
62
63func ExampleCloseStatus() {
64 // Dials a server and then expects to be disconnected with status code
65 // websocket.StatusNormalClosure.
66
67 ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
68 defer cancel()
69
70 c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
71 if err != nil {
72 log.Fatal(err)
73 }
74 defer c.CloseNow()
75
76 _, _, err = c.Reader(ctx)
77 if websocket.CloseStatus(err) != websocket.StatusNormalClosure {
78 log.Fatalf("expected to be disconnected with StatusNormalClosure but got: %v", err)
79 }
80}
81
82func Example_writeOnly() {
83 // This handler demonstrates how to correctly handle a write only WebSocket connection.

Callers

nothing calls this directly

Calls 4

DialFunction · 0.92
CloseStatusFunction · 0.92
CloseNowMethod · 0.45
ReaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…