paths walk

This commit is contained in:
alessio 2016-07-30 01:02:11 +02:00
parent 3d36e57ad9
commit 3fe830030f
2 changed files with 40 additions and 1 deletions

View File

@ -1 +0,0 @@
package realize

40
realize/watcher.go Normal file
View File

@ -0,0 +1,40 @@
package realize
import (
"github.com/fsnotify/fsnotify"
"path/filepath"
"os"
)
func (h *Config) Watch() error{
watcher, err := fsnotify.NewWatcher()
if err != nil{
panic(err)
}
walking := func(path string, info os.FileInfo, err error) error{
if info.IsDir() {
if err = watcher.Add(path); err != nil {
return filepath.SkipDir
}
}
return nil
}
// check file
if err := h.Read(); err == nil {
// loop projects
for _, val := range h.Projects {
// add paths to watcher
for _, path := range val.Watcher.Paths {
if err := filepath.Walk(path, walking); err != nil{
panic(err)
}
}
}
return nil
}else{
return err
}
}