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

       在項目中使用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()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章