예제 #1
0
파일: main.go 프로젝트: jksy/go-log-viewer
func prepareReader(conf *config.Config, readCh chan []byte) {
	for _, v := range conf.Inputs {
		u, err := url.Parse(v)
		if err != nil {
			log.Printf("input url parse error:%s, %s", v, err.Error())
		}
		if u.Scheme != "file" {
			log.Printf("cant support [%s] scheme, %s", u.Scheme, v)
			continue
		}
		fileReader := reader.NewFileReaderWithOpen(u.Path, readCh)
		go fileReader.Run()
	}
}
예제 #2
0
func TestFileAppend(t *testing.T) {
	withTempfile(t, func(testFile *os.File) {
		ch := make(chan []byte)
		fileReader := reader.NewFileReaderWithOpen(testFile.Name(), ch)
		go fileReader.Run()

		str := randomString()
		bin := []byte(str)
		testFile.Write(bin)

		select {
		case readed := <-ch:
			if string(readed[:]) != str {
				t.Error("dont same string, %v:%v", str, string(readed[:]))
			}
		case <-time.After(1 * time.Second):
			t.Error("cant read channel from file")
		}
	})
}