Skip to content

Instantly share code, notes, and snippets.

@1f604
Created June 20, 2021 21:52
Show Gist options
  • Save 1f604/a619fe8a7ff80b4929cff7d1a8d563ab to your computer and use it in GitHub Desktop.
Save 1f604/a619fe8a7ff80b4929cff7d1a8d563ab to your computer and use it in GitHub Desktop.
file stat poll golang
import (
"fmt"
"io"
"log"
"os"
"time"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
const N = 1000
ticker := time.NewTicker(time.Second / N)
var lastmodtime int64 = 0
for range ticker.C {
fileinfo, err := os.Stat("/tmp/foo")
if err != nil {
panic(err)
}
modtime := fileinfo.ModTime().UnixNano()
if modtime != lastmodtime {
lastmodtime = modtime
fmt.Println(modtime)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment