golang-pitfalls-standard-library
Installation
SKILL.md
Golang Pitfalls: Standard Library
Source material: mistakes #75-81 from 100 Go Mistakes and How to Avoid Them (teivah/100-go-mistakes).
Apply these rules when working with the Go standard library.
75. Providing a wrong time duration (#75)
time.Durationis an alias forint64; one unit = one nanosecond (not a millisecond).time.NewTicker(1000)ticks every 1000 ns = 1 µs, not 1 second.- Always express durations through the
timeAPI:time.Second,1000 * time.Nanosecond,time.Millisecond. Avoid raw numbers.
76. time.After and memory leaks (#76)
- Not relevant anymore from Go 1.23 — the internal timer implementation was fixed. On older Go versions,
time.Afterinside a loop kept timers alive until fired; usetime.NewTimer/time.NewTickerwithdefer Stop()if you target pre-1.23.