parent
7c929bd599
commit
97271a7dce
|
@ -3,6 +3,7 @@ package inputreader
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
"github.com/rjeczalik/notify"
|
"github.com/rjeczalik/notify"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
@ -13,7 +14,7 @@ import (
|
||||||
// and behaves like a reader
|
// and behaves like a reader
|
||||||
type FileWatcherReader struct {
|
type FileWatcherReader struct {
|
||||||
// Folder to watch
|
// Folder to watch
|
||||||
folderfd *os.File
|
folderstr string
|
||||||
// Notify Channel
|
// Notify Channel
|
||||||
eic chan notify.EventInfo
|
eic chan notify.EventInfo
|
||||||
// TearDown channel
|
// TearDown channel
|
||||||
|
@ -30,9 +31,9 @@ type FileWatcherReader struct {
|
||||||
|
|
||||||
// NewFileWatcherReader creates a new FileWatcherReader
|
// NewFileWatcherReader creates a new FileWatcherReader
|
||||||
// json specifies whether we now we handle json files
|
// json specifies whether we now we handle json files
|
||||||
func NewFileWatcherReader(f *os.File, j bool) (*FileWatcherReader, error) {
|
func NewFileWatcherReader(f string, j bool) (*FileWatcherReader, error) {
|
||||||
r := &FileWatcherReader{
|
r := &FileWatcherReader{
|
||||||
folderfd: f,
|
folderstr: f,
|
||||||
eic: make(chan notify.EventInfo, 4096),
|
eic: make(chan notify.EventInfo, 4096),
|
||||||
json: j,
|
json: j,
|
||||||
watching: true,
|
watching: true,
|
||||||
|
@ -40,7 +41,7 @@ func NewFileWatcherReader(f *os.File, j bool) (*FileWatcherReader, error) {
|
||||||
}
|
}
|
||||||
// go routine holding the watcher
|
// go routine holding the watcher
|
||||||
go func() {
|
go func() {
|
||||||
if err := notify.Watch("./...", r.eic, notify.InCloseWrite); err != nil {
|
if err := notify.Watch(fmt.Sprintf("%s/...", r.folderstr ), r.eic, notify.InCloseWrite); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer notify.Stop(r.eic)
|
defer notify.Stop(r.eic)
|
||||||
|
|
Loading…
Reference in New Issue