fix:调整值接收器和指针接收器
This commit is contained in:
parent
6e49288dcf
commit
da72ee978f
|
@ -18,7 +18,7 @@ func init() {
|
|||
system.RegisterInit(initOrderEnsureTables, &ensureTables{})
|
||||
}
|
||||
|
||||
func (ensureTables) InitializerName() string {
|
||||
func (e *ensureTables) InitializerName() string {
|
||||
return "ensure_tables_created"
|
||||
}
|
||||
func (e *ensureTables) InitializeData(ctx context.Context) (next context.Context, err error) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package request
|
||||
|
||||
// Casbin info structure
|
||||
// CasbinInfo Casbin info structure
|
||||
type CasbinInfo struct {
|
||||
Path string `json:"path"` // 路径
|
||||
Method string `json:"method"` // 方法
|
||||
}
|
||||
|
||||
// Casbin structure for input parameters
|
||||
// CasbinInReceive Casbin structure for input parameters
|
||||
type CasbinInReceive struct {
|
||||
AuthorityId uint `json:"authorityId"` // 权限id
|
||||
CasbinInfos []CasbinInfo `json:"casbinInfos"`
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
)
|
||||
|
||||
// Add menu authority info structure
|
||||
// AddMenuAuthorityInfo Add menu authority info structure
|
||||
type AddMenuAuthorityInfo struct {
|
||||
Menus []system.SysBaseMenu `json:"menus"`
|
||||
AuthorityId uint `json:"authorityId"` // 角色ID
|
||||
|
|
|
@ -18,7 +18,7 @@ type Register struct {
|
|||
Email string `json:"email" example:"电子邮箱"`
|
||||
}
|
||||
|
||||
// User login structure
|
||||
// Login User login structure
|
||||
type Login struct {
|
||||
Username string `json:"username"` // 用户名
|
||||
Password string `json:"password"` // 密码
|
||||
|
@ -26,19 +26,19 @@ type Login struct {
|
|||
CaptchaId string `json:"captchaId"` // 验证码ID
|
||||
}
|
||||
|
||||
// Modify password structure
|
||||
// ChangePasswordReq Modify password structure
|
||||
type ChangePasswordReq struct {
|
||||
ID uint `json:"-"` // 从 JWT 中提取 user id,避免越权
|
||||
Password string `json:"password"` // 密码
|
||||
NewPassword string `json:"newPassword"` // 新密码
|
||||
}
|
||||
|
||||
// Modify user's auth structure
|
||||
// SetUserAuth Modify user's auth structure
|
||||
type SetUserAuth struct {
|
||||
AuthorityId uint `json:"authorityId"` // 角色ID
|
||||
}
|
||||
|
||||
// Modify user's auth structure
|
||||
// SetUserAuthorities Modify user's auth structure
|
||||
type SetUserAuthorities struct {
|
||||
ID uint
|
||||
AuthorityIds []uint `json:"authorityIds"` // 角色ID
|
||||
|
|
|
@ -169,8 +169,8 @@ func (casbinService *CasbinService) AddPolicies(db *gorm.DB, rules [][]string) e
|
|||
return db.Create(&casbinRules).Error
|
||||
}
|
||||
|
||||
func (CasbinService *CasbinService) FreshCasbin() (err error) {
|
||||
e := CasbinService.Casbin()
|
||||
func (casbinService *CasbinService) FreshCasbin() (err error) {
|
||||
e := casbinService.Casbin()
|
||||
err = e.LoadPolicy()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (i *initExaFileMysql) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&example.ExaFileUploadAndDownload{})
|
||||
}
|
||||
|
||||
func (i initExaFileMysql) InitializerName() string {
|
||||
func (i *initExaFileMysql) InitializerName() string {
|
||||
return example.ExaFileUploadAndDownload{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func init() {
|
|||
system.RegisterInit(initOrderApi, &initApi{})
|
||||
}
|
||||
|
||||
func (i initApi) InitializerName() string {
|
||||
func (i *initApi) InitializerName() string {
|
||||
return sysModel.SysApi{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func init() {
|
|||
system.RegisterInit(initOrderApiIgnore, &initApiIgnore{})
|
||||
}
|
||||
|
||||
func (i initApiIgnore) InitializerName() string {
|
||||
func (i *initApiIgnore) InitializerName() string {
|
||||
return sysModel.SysIgnoreApi{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ func (i *initMenuAuthority) TableCreated(ctx context.Context) bool {
|
|||
return false // always replace
|
||||
}
|
||||
|
||||
func (i initMenuAuthority) InitializerName() string {
|
||||
func (i *initMenuAuthority) InitializerName() string {
|
||||
return "sys_menu_authorities"
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,13 @@ func (i *initMenuAuthority) InitializeData(ctx context.Context) (next context.Co
|
|||
if !ok {
|
||||
return ctx, system.ErrMissingDBContext
|
||||
}
|
||||
authorities, ok := ctx.Value(initAuthority{}.InitializerName()).([]sysModel.SysAuthority)
|
||||
initAuth := &initAuthority{}
|
||||
authorities, ok := ctx.Value(initAuth.InitializerName()).([]sysModel.SysAuthority)
|
||||
if !ok {
|
||||
return ctx, errors.Wrap(system.ErrMissingDependentContext, "创建 [菜单-权限] 关联失败, 未找到权限表初始化数据")
|
||||
}
|
||||
menus, ok := ctx.Value(initMenu{}.InitializerName()).([]sysModel.SysBaseMenu)
|
||||
initMen := &initMenu{}
|
||||
menus, ok := ctx.Value(initMen.InitializerName()).([]sysModel.SysBaseMenu)
|
||||
if !ok {
|
||||
return next, errors.Wrap(errors.New(""), "创建 [菜单-权限] 关联失败, 未找到菜单表初始化数据")
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func (i *initAuthority) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysAuthority{})
|
||||
}
|
||||
|
||||
func (i initAuthority) InitializerName() string {
|
||||
func (i *initAuthority) InitializerName() string {
|
||||
return sysModel.SysAuthority{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func (i *initCasbin) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&adapter.CasbinRule{})
|
||||
}
|
||||
|
||||
func (i initCasbin) InitializerName() string {
|
||||
func (i *initCasbin) InitializerName() string {
|
||||
var entity adapter.CasbinRule
|
||||
return entity.TableName()
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (i *initDict) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysDictionary{})
|
||||
}
|
||||
|
||||
func (i initDict) InitializerName() string {
|
||||
func (i *initDict) InitializerName() string {
|
||||
return sysModel.SysDictionary{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func (i *initDictDetail) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysDictionaryDetail{})
|
||||
}
|
||||
|
||||
func (i initDictDetail) InitializerName() string {
|
||||
func (i *initDictDetail) InitializerName() string {
|
||||
return sysModel.SysDictionaryDetail{}.TableName()
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,9 @@ func (i *initDictDetail) InitializeData(ctx context.Context) (context.Context, e
|
|||
if !ok {
|
||||
return ctx, system.ErrMissingDBContext
|
||||
}
|
||||
dicts, ok := ctx.Value(initDict{}.InitializerName()).([]sysModel.SysDictionary)
|
||||
dictKey := (&initDict{}).InitializerName()
|
||||
dicts, ok := ctx.Value(dictKey).([]sysModel.SysDictionary)
|
||||
//dicts, ok := ctx.Value(initDict{}.InitializerName()).([]sysModel.SysDictionary)
|
||||
if !ok {
|
||||
return ctx, errors.Wrap(system.ErrMissingDependentContext,
|
||||
fmt.Sprintf("未找到 %s 表初始化数据", sysModel.SysDictionary{}.TableName()))
|
||||
|
|
|
@ -17,7 +17,7 @@ func init() {
|
|||
system.RegisterInit(initOrderExcelTemplate, &initExcelTemplate{})
|
||||
}
|
||||
|
||||
func (i initExcelTemplate) InitializerName() string {
|
||||
func (i *initExcelTemplate) InitializerName() string {
|
||||
return "sys_export_templates"
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ func init() {
|
|||
system.RegisterInit(initOrderMenu, &initMenu{})
|
||||
}
|
||||
|
||||
func (i initMenu) InitializerName() string {
|
||||
func (i *initMenu) InitializerName() string {
|
||||
return SysBaseMenu{}.TableName()
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ func (i *initUser) TableCreated(ctx context.Context) bool {
|
|||
return db.Migrator().HasTable(&sysModel.SysUser{})
|
||||
}
|
||||
|
||||
func (i initUser) InitializerName() string {
|
||||
func (i *initUser) InitializerName() string {
|
||||
return sysModel.SysUser{}.TableName()
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,8 @@ func (i *initUser) InitializeData(ctx context.Context) (next context.Context, er
|
|||
return ctx, errors.Wrap(err, sysModel.SysUser{}.TableName()+"表数据初始化失败!")
|
||||
}
|
||||
next = context.WithValue(ctx, i.InitializerName(), entities)
|
||||
authorityEntities, ok := ctx.Value(initAuthority{}.InitializerName()).([]sysModel.SysAuthority)
|
||||
initAuth := &initAuthority{}
|
||||
authorityEntities, ok := ctx.Value(initAuth.InitializerName()).([]sysModel.SysAuthority)
|
||||
if !ok {
|
||||
return next, errors.Wrap(system.ErrMissingDependentContext, "创建 [用户-权限] 关联失败, 未找到权限表初始化数据")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue