writeMessage writes a message to the SSE stream
(msg SSEMessage)
| 167 | |
| 168 | // writeMessage writes a message to the SSE stream |
| 169 | func (h *SSEHandlerCh) writeMessage(msg SSEMessage) error { |
| 170 | if h.ctx.Err() != nil { |
| 171 | return h.ctx.Err() |
| 172 | } |
| 173 | switch msg.Type { |
| 174 | case SSEMsgData: |
| 175 | return h.writeDirectly(msg.Data, SSEMsgData) |
| 176 | case SSEMsgEvent: |
| 177 | return h.writeEvent(msg.EventType, msg.Data) |
| 178 | case SSEMsgComment: |
| 179 | return h.writeDirectly(msg.Data, SSEMsgComment) |
| 180 | case SSEMsgError: |
| 181 | return h.writeDirectly(msg.Data, SSEMsgData) |
| 182 | default: |
| 183 | return fmt.Errorf("unknown message type: %s", msg.Type) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // isInitialized returns whether SetupSSE has been called |
| 188 | func (h *SSEHandlerCh) isInitialized() bool { |
no test coverage detected