func (_tailer *Tailer) loop() { transcript.TraceDebugging("running tailer...") var _error error var _offset int64 transcript.TraceDebugging("opening tailer file...") _tailer.file, _error = os.Open(_tailer.path) if _error != nil { transcript.TraceError("error encountered while opening tailer file; aborting...") panic(_error) } defer _tailer.file.Close() _offset, _error = _tailer.file.Seek(0, os.SEEK_END) if _error != nil { transcript.TraceWarning("error encountered while positioning tailer file; ignoring...") } _tailer.pushIdentifier, _tailer.pushChannel = _tailer.router.CreateInbound() defer _tailer.router.UnregisterInbound(_tailer.pushIdentifier) _reader := bufio.NewReader(_tailer.file) for _counter := 0; ; _counter += 1 { _line, _error := _reader.ReadBytes('\n') if _error == io.EOF { time.Sleep(100 * time.Millisecond) continue } if _error != nil { transcript.TraceError("error encountered while reading tailer file; aborting...") panic(_error) } if (_counter == 0) && (_offset != 0) { continue } _tailer.pushChannel <- Event{Payload: _line} } }
func (_streamer *Streamer) loop() { transcript.TraceDebugging("starting http streamer...") _error := _streamer.server.ListenAndServe() if _error != nil { transcript.TraceError("error encountered while starting http streamer: `%s`; aborting...", _error.Error()) panic(_error) } }
func (_server *Streamer) ServeHTTP(_writer http.ResponseWriter, _request *http.Request) { transcript.TraceDebugging("serving stream...") _pullChannel := make(chan Event, 1024) _pullIdentifier := _server.router.RegisterOutbound(_pullChannel) defer _server.router.UnregisterOutbound(_pullIdentifier) _headers := _writer.Header() _headers.Set("Content-Type", "text/plain") _writer.WriteHeader(http.StatusOK) for { _event := <-_pullChannel _, _error := _writer.Write(_event.Payload) if _error != nil { transcript.TraceError("error encountered while serving stream: `%s`; closing...", _error.Error()) return } _writer.(http.Flusher).Flush() } }