models

package
v1.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModel

type BaseModel struct {
	ID        uint32 `gorm:"autoIncrement;primaryKey"`
	CreatedAt uint32 `gorm:"autoCreateTime`      // 使用时间戳秒数填充创建时间
	UpdatedAt uint32 `gorm:"autoUpdateTime`      // 使用时间戳秒数填充创建时间
	Status    uint8  `gorm:"default:1;not null"` // 状态
}

type Permission

type Permission struct {
	BaseModel
	Name        string `gorm:"not null;default: '';uniqueIndex" validate:"required"`                            // 权限名称,必填,唯一
	Description string `gorm:"not null;default: '';"`                                                           // 描述
	Method      string `gorm:"not null;default: '';index"`                                                      // 请求方法
	Url         string `gorm:"not null;default: '';" validate:"required"`                                       // 绑定的 url,必填,在我看来一个权限如果不绑定url那是无意义的
	UrlMd5      string `gorm:"type:char(32);not null;default: '';index"`                                        // 绑定 url 的 md5,用来检索
	ModelName   string `gorm:"not null;default: '';" validate:"required_with=UrlParamName ModelCheckCondition"` // 绑定的模型名称,这个是用来进行进一步验证用的
	//GetModelFieldName   string  `gorm:"not null;default: ”;"`                                        // 获取模型用的字段名称,跟绑定模型合用,所以 path 的变量名和 数据库的字段名要一致
	UrlParamName        string  `gorm:"not null;default: '';" validate:"required_with=ModelName ModelCheckCondition"` // 从 url 获取参数的字段名
	ModelCheckCondition string  `gorm:"not null;default: '';" validate:"required_with=ModelName UrlParamName"`        // 绑定的模型名称跟登录用户的判定条件,这个准备实现一个自己的语义逻辑
	Rules               []*Rule `gorm:"many2many:rule_permissions;"`
}

权限

func (*Permission) Add

func (p *Permission) Add() error

增加

func (*Permission) BeforeCreate

func (p *Permission) BeforeCreate(_ *gorm.DB) (err error)

func (*Permission) BeforeUpdate added in v1.0.14

func (p *Permission) BeforeUpdate(_ *gorm.DB) (err error)

func (*Permission) Delete

func (p *Permission) Delete() (int64, error)

删除

func (*Permission) Update

func (p *Permission) Update() error

更新

type Rule

type Rule struct {
	BaseModel
	Name        string       `gorm:"not null;default: '';uniqueIndex" validate:"required"` // 权限名称,必填,唯一
	Description string       `gorm:"not null;default: '';"`                                // 描述
	Permissions []Permission `gorm:"many2many:rule_permissions;"`
}

角色

func (*Rule) Add

func (r *Rule) Add() error

增加

func (*Rule) AttachPermission

func (r *Rule) AttachPermission(p []Permission) (*Rule, error)

角色添加权限

func (*Rule) ClearPermission

func (r *Rule) ClearPermission() (*Rule, error)

清空角色的所有权限

func (*Rule) Delete

func (r *Rule) Delete() (int64, error)

删除

func (*Rule) ReplacePermission

func (r *Rule) ReplacePermission(p []Permission) (*Rule, error)

将角色权限替换为新的权限列表

func (*Rule) Update

func (r *Rule) Update() error

更新 - 这个只更新本体,不要更新关联权限相关,权限相关用后面权限相关的方法

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL