Documentation
¶
Overview ¶
This package enables the use of the github.com/coder/websocket package with the ws-server-wrapper library. It provides an adapter between a Conn from the github.com/coder/websocket package and a Conn in the ws-server-wrapper library.
Example ¶
// Create ws-wrapper-server and "echo" event handler. Note that the event // handler function may optionally have a context as its first argument, // it must always return 2 values, and the second value must implement // error. wsServer := wrapper.NewServer() wsServer.On("echo", func(s string) (string, error) { // If a ws-server client sends a "echo" request, it will receive the // echoed response. return s, nil }) // Create HTTP handler function that upgrades the HTTP connection to a // WebSocket using the github.com/coder/websocket package. h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { conn, err := websocket.Accept(w, r, &websocket.AcceptOptions{ // options go here (i.e. cross-origin setting)... }) if err != nil { // websocket.Accept already writes the HTTP response return } // Attach the WebSocket connection to ws-server-wrapper and start // listening for inbound messages. err = wsServer.Accept(Wrap(conn)) if err != nil { // wsServer.Accept already closes the conn return } }) // Start the HTTP server log.Fatal(http.ListenAndServe("localhost:8080", h))
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.