package models import ( "time" "gorm.io/gorm" ) var tablePrefix = "" // SetTablePrefix 设置表前缀(由 database 包调用) func SetTablePrefix(prefix string) { tablePrefix = prefix } // User 用户模型 type User struct { ID uint `gorm:"primarykey" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` Username string `gorm:"uniqueIndex;not null;size:50" json:"username"` Email string `gorm:"uniqueIndex;not null;size:100" json:"email"` Password string `gorm:"not null;size:255" json:"-"` // 不返回密码 IsAdmin bool `gorm:"default:false" json:"is_admin"` IsActive bool `gorm:"default:true" json:"is_active"` } // TableName 指定表名(支持前缀) func (u User) TableName() string { if tablePrefix != "" { return tablePrefix + "users" } return "users" }