Documentation
¶
Index ¶
- Variables
- func CloseDB() error
- func GetAllPermission() *[]Permission
- func GetPermissionByUser(user *User) *[]Permission
- func InitDatabase(password string)
- func Setup() (err error)
- type BaseModel
- type BaseModelNoUpdateTime
- type BaseModelTime
- type ControlBy
- type Department
- type GormLogger
- func (gl *GormLogger) Error(ctx context.Context, msg string, values ...interface{})
- func (gl *GormLogger) Info(ctx context.Context, msg string, values ...interface{})
- func (gl *GormLogger) LogMode(level gormLogger.LogLevel) gormLogger.Interface
- func (gl *GormLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (gl *GormLogger) Warn(ctx context.Context, msg string, values ...interface{})
- type LoginLog
- type Permission
- type Role
- type Tree
- type User
Constants ¶
This section is empty.
Variables ¶
View Source
var DB *gorm.DB
Functions ¶
func GetAllPermission ¶
func GetAllPermission() *[]Permission
func GetPermissionByUser ¶
func GetPermissionByUser(user *User) *[]Permission
func InitDatabase ¶
func InitDatabase(password string)
Types ¶
type BaseModel ¶
type BaseModel struct {
Id uint `json:"id" gorm:"primaryKey;autoIncrement;comment:主键ID"`
}
type BaseModelNoUpdateTime ¶
type BaseModelTime ¶
type ControlBy ¶
type Department ¶
type Department struct {
BaseModel
Name string `json:"name" gorm:"unique;not null;type:varchar(32);comment:部门名称"`
ParentId uint `json:"parentId" gorm:"comment:上级部门"`
ControlBy
BaseModelTime
}
func (Department) TableName ¶
func (Department) TableName() string
type GormLogger ¶
type GormLogger struct {
gormLogger.Interface
SlowThreshold time.Duration
IgnoreRecordNotFoundError bool
// contains filtered or unexported fields
}
func NewGormLogger ¶
func NewGormLogger(logger *zap.Logger, logLevel gormLogger.LogLevel, slowThreshold time.Duration, ignoreRecordNotFoundError bool) *GormLogger
func (*GormLogger) Error ¶
func (gl *GormLogger) Error(ctx context.Context, msg string, values ...interface{})
func (*GormLogger) Info ¶
func (gl *GormLogger) Info(ctx context.Context, msg string, values ...interface{})
func (*GormLogger) LogMode ¶
func (gl *GormLogger) LogMode(level gormLogger.LogLevel) gormLogger.Interface
type LoginLog ¶
type LoginLog struct {
BaseModel
// IPV6最大长度 39 位
Ip string `json:"ip" gorm:"type:varchar(40);comment:IP地址"`
Location string `json:"location" gorm:"type:varchar(64);comment:地点"`
Client string `json:"client" gorm:"type:varchar(255);comment:客户端"`
Os string `json:"os" gorm:"type:varchar(255);comment:操作系统"`
Status bool `json:"status" gorm:"type:bool;comment:成功或者失败"`
Kind string `json:"kind" gorm:"type:varchar(32);comment:日志类型"`
Detail string `json:"detail" gorm:"type:varchar(255);comment:操作详情"`
DeptId uint `json:"deptId" gorm:"comment:部门ID"`
ControlBy
BaseModelNoUpdateTime
}
type Permission ¶
type Permission struct {
BaseModel
Name string `json:"name" gorm:"unique;not null;type:varchar(32);comment:'权限名称'"`
// 前端验证用
Sign string `json:"sign" gorm:"unique;not null;type:varchar(32);comment:'权限标识'"`
Menu bool `json:"menu" gorm:"not null;type:bool;comment:'是否为左侧菜单'"`
Method string `json:"method" gorm:"not null;type:varchar(8);comment:'HTTP请求方法'"`
Path string `json:"path" gorm:"not null;type:varchar(256);comment:'HTTP请求路径正则'"`
ParentId uint `json:"parentId" gorm:"comment:上级权限"`
BaseModelTime
Roles []Role `json:"roles" gorm:"many2many:role_permission"`
}
func (Permission) TableName ¶
func (Permission) TableName() string
type Role ¶
type Role struct {
BaseModel
Name string `json:"name" gorm:"unique;not null;type:varchar(32);comment:角色名称"`
DeptId uint `json:"deptId" gorm:"comment:部门ID"`
ControlBy
BaseModelTime
Permissions []Permission `json:"permissions" gorm:"many2many:role_permission"`
}
type Tree ¶
type Tree struct {
Id uint `json:"id"`
Label string `json:"label"`
Children []*Tree `json:"children"`
}
func GetPerm ¶
func GetPerm(from uint, permissions *[]Permission) (perms []Tree)
type User ¶
type User struct {
BaseModel
Username string `json:"username" gorm:"unique;not null;type:varchar(32);comment:用户名"`
Name string `json:"name" gorm:"type:varchar(32);comment:姓名"`
Avatar string `json:"avatar" gorm:"type:varchar(255);comment:头像"`
// sha256 加密,固定64位
Password string `json:"-" gorm:"not null;type:char(64);comment:密码"`
IsSuper bool `json:"isSuper" gorm:"not null;type:bool;comment:是否为超级管理员"`
Status bool `json:"status" gorm:"not null;type:bool;comment:是否启用"`
Mobile string `json:"mobile" gorm:"type:char(11);comment:'手机'"`
Email string `json:"email" gorm:"type:varchar(255);comment:'邮箱'"`
// 未使用 gorm 自带的一对多实现
// 采用了在一对多的两个实体间,在“多”的实体表(即用户)中新增一个字段,该字段是“一”实体表(即部门)的主键。
DeptId uint `json:"deptId" gorm:"comment:部门ID"`
RoleId uint `json:"roleId" gorm:"comment:角色ID"`
DeptIds []uint `json:"-" gorm:"-"`
RoleIds []uint `json:"-" gorm:"-"`
// 权限标识
Permissions []string `json:"permissions" gorm:"-"`
ControlBy
BaseModelTime
}
func (*User) GetPermissions ¶
func (u *User) GetPermissions()
Click to show internal directories.
Click to hide internal directories.