Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename Rules to Actions, use them in Monitor#run()

  • Loading branch information...
commit ad257376598281a636ea9507433fb6b58a00bb85 1 parent ee5d8e3
@mrnugget authored
View
17 watchgopher/actions.go
@@ -0,0 +1,17 @@
+package watchgopher
+
+import (
+ "fmt"
+ "os"
+ "regexp"
+)
+
+type Action func(string, os.FileInfo)
+
+func Unzipper(path string, fi os.FileInfo) {
+ ok, err := regexp.MatchString(`^.*\.zip$`, path)
+
+ if err == nil && ok {
+ fmt.Println("IT IS A ZIP!")
+ }
+}
View
14 watchgopher/monitor.go
@@ -12,14 +12,16 @@ func Watch(path string, interval time.Duration) {
dir := NewDir(path)
ticker := time.Tick(interval)
+ actions := []Action{Unzipper}
- monitor := &Monitor{dir, ticker}
+ monitor := &Monitor{dir, ticker, actions}
monitor.start()
}
type Monitor struct {
- dir *Dir
- ticker <-chan time.Time
+ dir *Dir
+ ticker <-chan time.Time
+ actions []Action
}
func (m *Monitor) start() {
@@ -39,5 +41,9 @@ func (m *Monitor) start() {
}
func (m *Monitor) run() {
- fmt.Println(m.dir.Files)
+ for fpath, finfo := range m.dir.Files {
+ for _, action := range m.actions {
+ action(fpath, finfo)
+ }
+ }
}
View
7 watchgopher/rules.go
@@ -1,7 +0,0 @@
-package watchgopher
-
-import (
- "os"
-)
-
-type Rule func(string, os.FileInfo)
Please sign in to comment.
Something went wrong with that request. Please try again.