package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type Model struct { ID string `gorm:"column:id;primaryKey;type:uuid;default:uuid_generate_v4()" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (m *Model) BeforeCreate(tx *gorm.DB) (err error) { if tx.Dialector.Name() == "mysql" && m.ID == "" { m.ID = uuid.New().String() } return }