summaryrefslogtreecommitdiff
path: root/spooler.go
diff options
context:
space:
mode:
Diffstat (limited to 'spooler.go')
-rw-r--r--spooler.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/spooler.go b/spooler.go
index 05dcf1a..4f0f508 100644
--- a/spooler.go
+++ b/spooler.go
@@ -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
+
+}