1. 程式人生 > 其它 >golang 使用time包碰到數字與時間相乘的問題

golang 使用time包碰到數字與時間相乘的問題

技術標籤:golanggolang

在專案中使用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()