config: update to fsnotify.v1
This commit is contained in:
+11
-5
@@ -11,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"bitbucket.org/kardianos/osext"
|
"bitbucket.org/kardianos/osext"
|
||||||
"code.google.com/p/go.exp/fsnotify"
|
"gopkg.in/fsnotify.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPostfix = "_config.json"
|
const DefaultPostfix = "_config.json"
|
||||||
@@ -65,7 +65,8 @@ type EncodeConfig func(w io.Writer, v interface{}) error
|
|||||||
|
|
||||||
type WatchConfig struct {
|
type WatchConfig struct {
|
||||||
// Notified here if the file changes.
|
// Notified here if the file changes.
|
||||||
C chan *WatchConfig
|
C chan *WatchConfig
|
||||||
|
Err chan error
|
||||||
|
|
||||||
filepath string
|
filepath string
|
||||||
watch *fsnotify.Watcher
|
watch *fsnotify.Watcher
|
||||||
@@ -100,13 +101,14 @@ func NewWatchConfig(filepath string, decode DecodeConfig, defaultConfig interfac
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = watch.WatchFlags(filepath, fsnotify.FSN_MODIFY|fsnotify.FSN_CREATE)
|
err = watch.Add(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
wc := &WatchConfig{
|
wc := &WatchConfig{
|
||||||
C: make(chan *WatchConfig),
|
C: make(chan *WatchConfig),
|
||||||
|
Err: make(chan error),
|
||||||
|
|
||||||
filepath: filepath,
|
filepath: filepath,
|
||||||
watch: watch,
|
watch: watch,
|
||||||
@@ -127,8 +129,12 @@ func (wc *WatchConfig) run() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-wc.close:
|
case <-wc.close:
|
||||||
|
close(wc.C)
|
||||||
|
close(wc.Err)
|
||||||
return
|
return
|
||||||
case <-wc.watch.Event:
|
case err := <-wc.watch.Errors:
|
||||||
|
wc.Err <- err
|
||||||
|
case <-wc.watch.Events:
|
||||||
trigger = true
|
trigger = true
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
// Think of this as a PLC state machine.
|
// Think of this as a PLC state machine.
|
||||||
|
|||||||
Reference in New Issue
Block a user