diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-07-06 22:05:29 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-07-06 22:05:29 +0100 |
commit | a678af8e1ca8982d550ee0fd034ad98ebaaa7747 (patch) | |
tree | cfa0c951bc07c3bf1e4a0907827413de41320e1e /spooler.go | |
parent | cde77203f00935eef102354077358d9d63a585b0 (diff) |
Preliminary stuff -- more work needed
Diffstat (limited to 'spooler.go')
-rw-r--r-- | spooler.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spooler.go b/spooler.go new file mode 100644 index 0000000..c0bc8a1 --- /dev/null +++ b/spooler.go @@ -0,0 +1,44 @@ +package main + +import ( + "github.com/fsnotify/fsnotify" + "log" + "os" +) + +// parse a request file and return a SCORSHmessage +func parse_request(fname string) (SCORSHmsg, error) { + + var ret SCORSHmsg + _, err := os.Open(fname) + if err != nil { + log.Printf("Unable to open file: %s\n", fname) + return ret, SCORSHErr(SCORSH_ERR_NO_FILE) + } + + return ret, nil + +} + +func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) { + + for { + select { + case event := <-watcher.Events: + if event.Op == fsnotify.Create { + msg, err := parse_request(event.Name) + if err != nil { + log.Printf("Invalid packet received. [%s]\n", err) + } + worker <- msg + } + case err := <-watcher.Errors: + log.Println("error:", err) + } + } +} + + +func main(){ + +} |