22 lines
304 B
Go
22 lines
304 B
Go
|
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
|
||
|
}
|