guesstimate/internal/model/base.go

22 lines
304 B
Go
Raw Permalink Normal View History

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
}