handleWriteWebsocket writes a Rabbit message to Websocket. A Rabbit consumer only passes a message. So, a Websocket connection is additionally passed using a closure.
(ws *websocket.Conn)
| 151 | // A Rabbit consumer only passes a message. So, a Websocket connection is |
| 152 | // additionally passed using a closure. |
| 153 | func handleWriteWebsocket(ws *websocket.Conn) func(d amqp.Delivery) error { |
| 154 | return func(d amqp.Delivery) error { |
| 155 | ws.SetWriteDeadline(time.Now().Add(10 * time.Second)) |
| 156 | // TODO: check msg |
| 157 | err := ws.WriteMessage(websocket.TextMessage, []byte(d.Body)) |
| 158 | if err != nil { |
| 159 | return fmt.Errorf("write websocket: %v", err) |
| 160 | } |
| 161 | return nil |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // handlePublishRabbit publishes a Websocket message to a Rabbit |
| 166 | // exchange with the the back-end and database routing keys. |