writeDirectly writes data directly to the response writer
(data string, msgType SSEMessageType)
| 193 | |
| 194 | // writeDirectly writes data directly to the response writer |
| 195 | func (h *SSEHandlerCh) writeDirectly(data string, msgType SSEMessageType) error { |
| 196 | if !h.isInitialized() { |
| 197 | panic("SSEHandlerCh not initialized - call SetupSSE first") |
| 198 | } |
| 199 | switch msgType { |
| 200 | case SSEMsgData: |
| 201 | _, err := fmt.Fprintf(h.w, "data: %s\n\n", data) |
| 202 | if err != nil { |
| 203 | return err |
| 204 | } |
| 205 | case SSEMsgComment: |
| 206 | _, err := fmt.Fprintf(h.w, ": %s\n\n", data) |
| 207 | if err != nil { |
| 208 | return err |
| 209 | } |
| 210 | default: |
| 211 | panic(fmt.Sprintf("unsupported direct write type: %s", msgType)) |
| 212 | } |
| 213 | return h.flush() |
| 214 | } |
| 215 | |
| 216 | // writeEvent writes an SSE event with optional event type |
| 217 | func (h *SSEHandlerCh) writeEvent(eventType, data string) error { |
no test coverage detected