recwatch 应该如何工作?

我正在尝试让recwatch工作。不过,我对它的界面感到困惑。是的,我可以创建一个观察者并向其中添加文件夹,但似乎没有一种方法可以启动允许我接收通知的事件循环。

原始代码中,有一个Run专门用于此目的的接收器。

我错过了什么吗?


慕侠2389804
浏览 176回答 1
1回答

收到一只叮咚

观察者一创建就开始发出事件。所需要做的就是从RecursiveWatcher.Watcher.Events. 例子:package mainimport (&nbsp; &nbsp; "fmt"&nbsp; &nbsp; "github.com/xyproto/recwatch")func main() {&nbsp; &nbsp; w, err := recwatch.NewRecursiveWatcher("sample_dir")&nbsp; &nbsp; if err != nil {&nbsp; &nbsp; &nbsp; &nbsp; panic(err)&nbsp; &nbsp; }&nbsp; &nbsp; for {&nbsp; &nbsp; &nbsp; &nbsp; select {&nbsp; &nbsp; &nbsp; &nbsp; case event := <-w.Events:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Printf("Event: %s\n", event)&nbsp; &nbsp; &nbsp; &nbsp; case event := <-w.Errors:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Printf("Error: %s\n", event)&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go