| 40 | } |
| 41 | |
| 42 | func ExampleDial() { |
| 43 | // Dials a server, writes a single JSON message and then |
| 44 | // closes the connection. |
| 45 | |
| 46 | ctx, cancel := context.WithTimeout(context.Background(), time.Minute) |
| 47 | defer cancel() |
| 48 | |
| 49 | c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil) |
| 50 | if err != nil { |
| 51 | log.Fatal(err) |
| 52 | } |
| 53 | defer c.CloseNow() |
| 54 | |
| 55 | err = wsjson.Write(ctx, c, "hi") |
| 56 | if err != nil { |
| 57 | log.Fatal(err) |
| 58 | } |
| 59 | |
| 60 | c.Close(websocket.StatusNormalClosure, "") |
| 61 | } |
| 62 | |
| 63 | func ExampleCloseStatus() { |
| 64 | // Dials a server and then expects to be disconnected with status code |