Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Last active Aug 29, 2015
Embed
What would you like to do?
// Writes stdin to output.log
package main
import (
"os"
"io"
)
func main() {
output, err := os.Create("output.log")
if err != nil {
panic(err)
}
defer output.Close()
_, err = io.Copy(output, os.Stdin)
if err != nil {
panic(err)
}
}
// Prints when output.log is modified
package main
import (
"fmt"
"github.com/howeyc/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
panic(err)
}
defer watcher.Close()
go func() {
for {
select {
case err := <-watcher.Error:
if err != nil {
panic(err)
}
case ev := <-watcher.Event:
fmt.Println(ev)
}
}
}()
err = watcher.Watch("output.log")
if err != nil {
panic(err)
}
select {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment