writeEvent writes an SSE event with optional event type
(eventType, data string)
| 215 | |
| 216 | // writeEvent writes an SSE event with optional event type |
| 217 | func (h *SSEHandlerCh) writeEvent(eventType, data string) error { |
| 218 | if !h.isInitialized() { |
| 219 | panic("SSEHandlerCh not initialized - call SetupSSE first") |
| 220 | } |
| 221 | if eventType != "" { |
| 222 | if _, err := fmt.Fprintf(h.w, "event: %s\n", eventType); err != nil { |
| 223 | return err |
| 224 | } |
| 225 | } |
| 226 | if _, err := fmt.Fprintf(h.w, "data: %s\n\n", data); err != nil { |
| 227 | return err |
| 228 | } |
| 229 | return h.flush() |
| 230 | } |
| 231 | |
| 232 | // flush attempts to flush the response writer |
| 233 | func (h *SSEHandlerCh) flush() error { |
no test coverage detected