目前需求:需要发现文件夹中有添加新日志,并输出起文件名。Github-项目地址
Example
package main
import (
“log”
“fmt”
“github.com/howeyc/fsnotify”
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
done := make(chan bool)
// Process events
go func() {
for {
select {
case ev := <-watcher.Event:
fmt.Println(ev)
fmt.Println(ev.IsCreate()) // True or False
// log.Println("event:", ev)
case err := <-watcher.Error:
log.Println("error:", err)
}
}
}()
err = watcher.Watch("/home/lee/go-workspace/src/lab/filedir")
if err != nil {
log.Fatal(err)
}
// Hang so program doesn't exit
<-done
/* ... do stuff ... */
watcher.Close()
}
[/go]