| 118 | } |
| 119 | |
| 120 | func Example_crossOrigin() { |
| 121 | // This handler demonstrates how to safely accept cross origin WebSockets |
| 122 | // from the origin example.com. |
| 123 | fn := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 124 | c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ |
| 125 | OriginPatterns: []string{"example.com"}, |
| 126 | }) |
| 127 | if err != nil { |
| 128 | log.Println(err) |
| 129 | return |
| 130 | } |
| 131 | c.Close(websocket.StatusNormalClosure, "cross origin WebSocket accepted") |
| 132 | }) |
| 133 | |
| 134 | err := http.ListenAndServe("localhost:8080", fn) |
| 135 | log.Fatal(err) |
| 136 | } |
| 137 | |
| 138 | func ExampleConn_Ping() { |
| 139 | // Dials a server and pings it 5 times. |