Created
June 20, 2021 21:52
-
-
Save 1f604/a619fe8a7ff80b4929cff7d1a8d563ab to your computer and use it in GitHub Desktop.
file stat poll golang
This file contains 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
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