deepakssn deepakssn - 1 year ago 163
reST (reStructuredText) Question

Golang: Broadcast messages to websocket when a particular POST JSON is received

I have an app that is connected to my goserver using websocket . I used this code to create a websocket connection -

http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
serveWs(hub, w, r)

When I receive a POST call I need to broadcast a message - "Order Received: " productNum to all the devices. productNum is received in the post request.


I want to know what I need to write in BroadcastMessage() to do this. Please help.

Answer Source

In BroadcastMessage, send a []byte to the hub's broadcast channel:

 hub.broadcast <- message
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download