在項目中使用time包時,睡眠時間時想要通過配置文件獲取,然而整數與時間相乘又報錯。如下
查詢time包發現
// 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
即,其實就是一個int64的數。最後先把需要的數字進行轉換,這樣解決即可
err = client.Set(ctx, key, data, time.Duration(ex)*time.Second).Err()