feat: RBAC 基本完成
This commit is contained in:
+6
-2
@@ -1,12 +1,14 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"sundynix-go/utils/uniqueid"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BaseModel struct {
|
||||
Id uint `gorm:"primarykey" json:"id"` // 主键ID
|
||||
Id string `gorm:"size:50;primaryKey" json:"id"` // 主键ID
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"` // 删除时间
|
||||
@@ -14,6 +16,8 @@ type BaseModel struct {
|
||||
|
||||
// BeforeCreate 定义一个钩子,在创建之前执行自动插入字段
|
||||
func (model BaseModel) BeforeCreate(db *gorm.DB) (err error) {
|
||||
//生成主键的string uniqueid
|
||||
db.Statement.SetColumn("id", uniqueid.GenerateId())
|
||||
db.Statement.SetColumn("created_at", time.Now())
|
||||
db.Statement.SetColumn("updated_at", time.Now())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user