我将变量存储到 MySQL 数据库中,字段类型VARCHAR(255)
如下:
ts, err := time.Parse(time.RFC3339, nonce[0:20])
效果很好,显示如下:
然后,当我需要从数据库中获取它时,我会这样做:
rows, err := db.Query("SELECT nonce, time FROM noncestore WHERE endpoint=?", endpoint)
var sTimeStamp, nonceHolder string
for rows.Next() {
err = rows.Scan(&nonceHolder, &sTimeStamp)
errCheck(err)
Gives error//>> timeStamp, err := time.Parse(time.RFC3339, sTimeStamp)
errCheck(err)
if timeStamp == ts && nonceHolder == s {
return errors.New("Nonce already used")
}
if now.Sub(timeStamp) < *maxNonceAge {
_, err := db.Query("INSERT INTO noncestore SET nonce=?, time=?, endpoint=?", nonceHolder, sTimeStamp, endpoint)
errCheck(err)
}
}
上面提到的行给了我这个错误:
2015/08/14 21:56:18 http: panic serving [::1]:49663: Failed: parsing time "2015-08-15 03:56:00" as "2006-01-02T15:04:05Z07:00": cannot parse " 03:56:00" as "T"
为什么它能够将其转换为并将其RFC3339
存储在数据库中,但是当需要获取它并将其格式化为RFC3339
以便我可以在我的 if 语句中使用时出现错误?