Golang把时间和数字相乘报错invalid operation: second * time.Second (mismatched types int and time.Duration)

在设置cookie过期时间的时候,用当日剩余秒数与内置变量相乘报错invalid operation: second * time.Second (mismatched types int and time.Duration)

 

Expires : time.Now().Add(10 * time.Second),//正常数字相乘没错

Expire:=12345
Expires : time.Now().Add(Expire * time.Second), //表达式相乘报错

Expire:=12345
Expires : time.Now().Add(time.Duration(Expire) * time.Second), //这样写就对了

 

posted @ 2020-10-09 20:38  温柔的风  阅读(7424)  评论(0编辑  收藏  举报