Pipe is used to create an in memory connection between two websockets analogous to net.Pipe.
(dialOpts *websocket.DialOptions, acceptOpts *websocket.AcceptOptions)
| 15 | // Pipe is used to create an in memory connection |
| 16 | // between two websockets analogous to net.Pipe. |
| 17 | func Pipe(dialOpts *websocket.DialOptions, acceptOpts *websocket.AcceptOptions) (clientConn, serverConn *websocket.Conn) { |
| 18 | tt := fakeTransport{ |
| 19 | h: func(w http.ResponseWriter, r *http.Request) { |
| 20 | serverConn, _ = websocket.Accept(w, r, acceptOpts) |
| 21 | }, |
| 22 | } |
| 23 | |
| 24 | if dialOpts == nil { |
| 25 | dialOpts = &websocket.DialOptions{} |
| 26 | } |
| 27 | _dialOpts := *dialOpts |
| 28 | dialOpts = &_dialOpts |
| 29 | dialOpts.HTTPClient = &http.Client{ |
| 30 | Transport: tt, |
| 31 | } |
| 32 | |
| 33 | clientConn, _, _ = websocket.Dial(context.Background(), "ws://example.com", dialOpts) |
| 34 | return clientConn, serverConn |
| 35 | } |
| 36 | |
| 37 | type fakeTransport struct { |
| 38 | h http.HandlerFunc |
searching dependent graphs…