deepakssn deepakssn - 7 months ago 77
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.


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

 hub.broadcast <- message