|
package model
|
|
|
|
import "time"
|
|
|
|
type Base struct {
|
|
ID int64 `gorm:"primary_key,AUTO_INCREMENT" json:"id"`
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func (b *Base) BeforeSave() (err error) {
|
|
now := time.Now()
|
|
|
|
if b.CreatedAt.IsZero() {
|
|
b.CreatedAt = now
|
|
}
|
|
|
|
b.UpdatedAt = now
|
|
|
|
return nil
|
|
}
|