Created
September 24, 2017 10:52
-
-
Save syossan27/0cfd27108af0c3f25f0891223476460a 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("./hoge.go") | |
| 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