(w http.ResponseWriter, r *http.Request)
| 6 | ) |
| 7 | |
| 8 | func (s *Service) GetLogs(w http.ResponseWriter, r *http.Request) { |
| 9 | flusher, ok := w.(http.Flusher) |
| 10 | if !ok { |
| 11 | http.Error(w, "Streaming unsupported", http.StatusInternalServerError) |
| 12 | return |
| 13 | } |
| 14 | |
| 15 | w.Header().Set("Content-Type", "text/event-stream") |
| 16 | w.Header().Set("Cache-Control", "no-cache") |
| 17 | w.Header().Set("Connection", "keep-alive") |
| 18 | |
| 19 | logChan := s.Backend().Logs() |
| 20 | |
| 21 | for { |
| 22 | select { |
| 23 | case log, ok := <-logChan: |
| 24 | if !ok { |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | _, err := fmt.Fprintf(w, "%s\n", log) |
| 29 | if err != nil { |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | flusher.Flush() |
| 34 | |
| 35 | case <-r.Context().Done(): |
| 36 | return |
| 37 | } |
| 38 | } |
| 39 | } |
nothing calls this directly
no test coverage detected