Go gotcha: Why can't I multiply a time.Duration with an integer?
Why doesn’t this compile?
invalid operation: n * time.Millisecond (mismatched types int and time.Duration)
There is no mixing of numeric types in Go.
You can only multiply a
- an untyped integer constant.
Here are three correct examples:
var n time.Duration = 100 time.Sleep(n * time.Millisecond)
const n = 100 time.Sleep(n * time.Millisecond)
time.Sleep(100 * time.Millisecond)