I cannot get mysql timestamp value in into a time.Time variable
I am trying to scan a row, All values get successfully scanned except the timestamp type in mysql, I am already using dsn parseTime=true which was one of the issues i searched into, but it does not help
type Tags struct {
ID int
CreatedAt time.Time `json:"created_at"`
}
func foo5() {
http.HandleFunc("/tags/", bar5)
http.ListenAndServe(":8080", nil)
}
func bar5(w http.ResponseWriter, r *http.Request) {
db, err := sql.Open("mysql", "root:*******@/catalogue_service?parseTime=true")
if err != nil {
fmt.Println("error opening")
}
v, _ := strconv.Atoi(path.Base(r.URL.Path))
row := db.QueryRow("select * from tags where id = ?", v)
var myRow Tags
row.Scan(&myRow.ID, &myRow.CreatedAt)
fmt.Println(myRow)
}
int and string values are displayed properly but CreatedAt prints 0001-01-01 00:00:00 +0000 UTC instead of the actual value
Edit:
+-----------------+--------------------------+------+-----+-------------------+-----------------------------------------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------------------+------+-----+-------------------+-----------------------------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | DEFAULT_GENERATED |
+-----------------+--------------------------+------+-----+-------------------+-----------------------------------------------+
| 84 | 2019-01-30 11:21:36 |