You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

32 lines
512 B

package models
import (
"time"
"github.com/gofrs/uuid"
"gorm.io/gorm"
)
// Base contains common columns for all tables.
type Base struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time `sql:"index"`
}
// BeforeCreate will set a UUID rather than numeric ID.
func (base *Base) BeforeCreate(tx *gorm.DB) error {
var (
id uuid.UUID
err error
)
id, err = uuid.NewV4()
if err != nil {
return err
}
base.ID = id
return nil
}