package model import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) // Base 基础模型 type Base struct { ID string `json:"id" gorm:"primaryKey;type:varchar(36)"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` } // BeforeCreate 自动生成UUID func (b *Base) BeforeCreate(tx *gorm.DB) error { if b.ID == "" { b.ID = uuid.New().String() } return nil }