- constants: 用户状态、性别、角色代码常量定义 - model: User/Role/UserRole GORM 模型 - dao: UserDAO (CRUD + 账号查询) + RoleDAO (角色分配/查询/检查) - provider: Auth 模块 Wire Provider Set Made-with: Cursor
30 lines
995 B
Go
30 lines
995 B
Go
package model
|
|
|
|
import "time"
|
|
|
|
// Role 角色表模型,对应 auth_roles 表
|
|
type Role struct {
|
|
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
Code string `json:"code" gorm:"uniqueIndex;size:50;not null"` // 角色代码: user/admin/super_admin
|
|
Name string `json:"name" gorm:"size:50;not null"` // 角色显示名称
|
|
Description string `json:"description" gorm:"size:200;default:''"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"not null;autoCreateTime"`
|
|
}
|
|
|
|
// TableName 指定数据库表名
|
|
func (Role) TableName() string {
|
|
return "auth_roles"
|
|
}
|
|
|
|
// UserRole 用户角色关联表模型,对应 auth_user_roles 表
|
|
type UserRole struct {
|
|
UserID int64 `json:"user_id" gorm:"primaryKey"`
|
|
RoleID int `json:"role_id" gorm:"primaryKey"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"not null;autoCreateTime"`
|
|
}
|
|
|
|
// TableName 指定数据库表名
|
|
func (UserRole) TableName() string {
|
|
return "auth_user_roles"
|
|
}
|