New watches a given glob paths array for changes
(paths []string, exclude []string, pollInterval time.Duration, callback Callback, log log.Logger)
| 40 | |
| 41 | // New watches a given glob paths array for changes |
| 42 | func New(paths []string, exclude []string, pollInterval time.Duration, callback Callback, log log.Logger) (Watcher, error) { |
| 43 | ignoreMatcher, err := ignoreparser.CompilePaths(exclude, log) |
| 44 | if err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | |
| 48 | watcher := &watcher{ |
| 49 | Paths: paths, |
| 50 | Exclude: ignoreMatcher, |
| 51 | PollInterval: pollInterval, |
| 52 | Callback: callback, |
| 53 | FileMap: make(map[string]os.FileInfo), |
| 54 | Log: log, |
| 55 | interrupt: make(chan bool), |
| 56 | } |
| 57 | |
| 58 | // Initialize filemap |
| 59 | _, _, err = watcher.Update() |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | |
| 64 | return watcher, nil |
| 65 | } |
| 66 | |
| 67 | // Start starts the watching process every second |
| 68 | func (w *watcher) Start() { |