(w http.ResponseWriter, ctx context.Context)
| 46 | } |
| 47 | |
| 48 | func NewSSE(w http.ResponseWriter, ctx context.Context) *SSE { |
| 49 | header := w.Header() |
| 50 | header.Set("Content-Type", "text/event-stream") |
| 51 | header.Set("Cache-Control", "no-cache") |
| 52 | header.Set("Connection", "keep-alive") |
| 53 | header.Set("X-Accel-Buffering", "no") |
| 54 | header.Set("Access-Control-Allow-Origin", "*") |
| 55 | return &SSE{ |
| 56 | ResponseWriter: w, |
| 57 | Context: ctx, |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func (sse *SSE) WriteJSON(data any) error { |
| 62 | return json.NewEncoder(sse).Encode(data) |
no test coverage detected