This question already has an answer here:
I'm getting an invalid operation: *timeout * time.Second (mismatched types int and time.Duration)
error when trying to run something similar to this
timeout := flag.Int("timeout", 30, "The time limit for answering questions.")
flag.Parse()
timeoutCh := time.After(*timeout * time.Second)
Just to be sure, I checked the type of *timeout
using reflect.TypeOf()
and it is in fact an int
. But if I do timeoutCh := time.After(30 * time.Second)
or use any other int
value the code works.
What am I missing here?