Created
September 24, 2017 11:42
-
-
Save syossan27/0a566ca7c82589d3399efd7aa4c48970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "log" | |
| "github.com/fsnotify/fsnotify" | |
| ) | |
| func main() { | |
| // watcherの作成 | |
| watcher, err := fsnotify.NewWatcher() | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| defer watcher.Close() | |
| // イベント監視 | |
| done := make(chan bool) | |
| go func() { | |
| for { | |
| select { | |
| case event := <-watcher.Events: | |
| log.Println("event:", event) | |
| case err := <-watcher.Errors: | |
| log.Println("error:", err) | |
| } | |
| } | |
| }() | |
| // hoge.goを含むディレクトリを監視対象に追加 | |
| err = watcher.Add("./test") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| <-done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment