diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-07-12 08:53:12 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-07-12 08:53:12 +0100 |
commit | b3ca09586c23831d9f089ab8a023580c403f8e55 (patch) | |
tree | 60bd13a7efe3a2ea210890fb9b486d6d68a90409 /spooler.go | |
parent | 32b09256150d139e77d04533f28d0c26a32b12bd (diff) |
reorganised types and modules
Diffstat (limited to 'spooler.go')
-rw-r--r-- | spooler.go | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -4,6 +4,7 @@ import ( "github.com/fsnotify/fsnotify" "log" "os" + "fmt" ) // parse a request file and return a SCORSHmessage @@ -22,7 +23,7 @@ func parse_request(fname string) (SCORSHmsg, error) { func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) { - + for { select { case event := <-watcher.Events: @@ -36,8 +37,25 @@ func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) { case err := <-watcher.Errors: log.Println("error:", err) } - } } +func StartSpooler(master *SCORSHmaster) error { + + watcher, err := fsnotify.NewWatcher() + + if err != nil { + return fmt.Errorf("Error creating watcher: %s\n", err) + } + + err = watcher.Add(master.Spooldir) + if err != nil { + return fmt.Errorf("Error adding folder: %s\n", err) + } + + go spooler(watcher, master.Spooler) + + return nil + +} |