// executable
if stat, err := os.Stat(filename); err != nil {
panic(err)
}
if stat.Mode().Perm() & 0111 == 0000 {
fmt.Printf("%s not executable\n", filename)
}
Last active
August 12, 2023 14:16
-
-
Save chaosmatrix/bc4a3d423273becbda3657102a12c5cd to your computer and use it in GitHub Desktop.
golang tips
time.Timer vs time.Ticker
Diff:
- Timer need to Reset every time when it fired
- Ticker auto reset every time when it fired
Warning:
- when the job wast more than ticker duration, there might has more than one job executed or lose some ticker
The difference of them show as code
// timer
for {
time.Sleep(d)
do_some_thing
// timer reset
}
// ticker
for {
time.Sleep(d)
go func() {
do_some_thing
}()
// wait next ticker
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
net/netip
Output: