如何解决尝试将新保存的模型作为JSON返回的错误。json: unsupported type: func() time.Time
user := database.DBConn.Create(&newUser)
return c.Status(http.StatusCreated).JSON(user) // fiber response
已尝试忽略时间戳字段。
type User struct {
gorm.Model
ID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
Phone string `json:"phone"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Email string `json:"email"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt time.Time `json:"-"`
}
还尝试了
CreatedAt time.Time `gorm:"type:timestamp" json:"created_at,string,omitempty"`
UpdatedAt time.Time `gorm:"type:timestamp" json:"updated_at,string,omitempty"`
DeletedAt time.Time `gorm:"type:timestamp" json:"deleted_at,string,omitempty"`
和
CreatedAt time.Time `gorm:"type:datetime" json:"created_at,string,omitempty"`
UpdatedAt time.Time `gorm:"type:datetime" json:"updated_at,string,omitempty"`
DeletedAt time.Time `gorm:"type:datetime" json:"deleted_at,string,omitempty"`
使用 gorm v1.20.12 和 Go 1.15.6
神不在的星期二
慕后森
相关分类