Skip to content

Instantly share code, notes, and snippets.

@sdomino
Last active October 1, 2021 04:08
Show Gist options
  • Save sdomino/746006ac626d6d00598a to your computer and use it in GitHub Desktop.
Save sdomino/746006ac626d6d00598a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/go-fsnotify/fsnotify"
)
// main
func main() {
// creates a new file watcher
watcher, err := fsnotify.NewWatcher()
if err != nil {
fmt.Println("ERROR", err)
}
defer watcher.Close()
//
done := make(chan bool)
//
go func() {
for {
select {
// watch for events
case event := <-watcher.Events:
fmt.Printf("EVENT! %#v\n", event)
// watch for errors
case err := <-watcher.Errors:
fmt.Println("ERROR", err)
}
}
}()
// out of the box fsnotify can watch a single file, or a single directory
if err := watcher.Add("/Users/skdomino/Desktop/test.html"); err != nil {
fmt.Println("ERROR", err)
}
<-done
}
@raifpy
Copy link

raifpy commented Jul 4, 2021

❤️

@imbdb
Copy link

imbdb commented Oct 1, 2021

Thank you for the code.
Please update github.com/go-fsnotify/fsnotify to github.com/fsnotify/fsnotify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment