Golang uses the time package to encounter the problem of multiplying numbers and time

       When using the time package in the project, I want to get the sleep time through the configuration file, but the integer multiplies the time and an error is reported. as follows

Query time package found

// A Duration represents the elapsed time between two instants
// as an int64 nanosecond count. The representation limits the
// largest representable duration to approximately 290 years.
type Duration int64

That is, it is actually an int64 number. Finally, first convert the required number, so that it can be solved

err = client.Set(ctx, key, data, time.Duration(ex)*time.Second).Err()

Guess you like

Origin blog.csdn.net/banfushen007/article/details/113139496