summaryrefslogtreecommitdiff
path: root/spooler.go
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-07-12 08:53:12 +0100
committerKatolaZ <katolaz@freaknet.org>2017-07-12 08:53:12 +0100
commitb3ca09586c23831d9f089ab8a023580c403f8e55 (patch)
tree60bd13a7efe3a2ea210890fb9b486d6d68a90409 /spooler.go
parent32b09256150d139e77d04533f28d0c26a32b12bd (diff)
reorganised types and modules
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
+
+}