How to multiply duration by integer?

To test concurrent goroutines, I added a line to a function to make it take a random time to return (up to one second)

time.Sleep(rand.Int31n(1000) * time.Millisecond)

However when I compiled, I got this error

.\crawler.go:49: invalid operation: rand.Int31n(1000) * time.Millisecond (mismatched types int32 and time.Duration)

Any ideas? How can I multiply a duration?

int32 and time.Duration are different types. You need to convert the int32 to a time.Duration , such as time.Sleep(time.Duration(rand.Int31n(1000)) * time.Millisecond) .