Golang:收到特定 POST JSON 时向 websocket 广播消息

我有一个使用 websocket 连接到我的 goserver 的应用程序。我使用此代码创建了一个 websocket 连接 - https://github.com/gorilla/websocket/tree/master/examples/chat


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

        serveWs(hub, w, r)

    })

当我收到一个 POST 电话时,我需要向所有设备广播一条消息 - “订单已收到:” productNum。在 post 请求中收到 productNum。


http.HandleFunc("/post",BroadcastMessage())

我想知道我需要在 BroadcastMessage() 中写什么来做到这一点。请帮忙。


杨__羊羊
浏览 313回答 1
1回答

翻过高山走不出你

在 BroadcastMessage 中,向[]byte集线器的广播频道发送一个:&nbsp;hub.broadcast&nbsp;<-&nbsp;message
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go