Skip to content

Commit

Permalink
chore: #1955 代码规范化。
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelmaxQm committed Dec 8, 2024
1 parent 31cfdac commit 9fdbeb2
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion server/source/example/file_upload_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions server/source/system/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const initOrderApi = system.InitOrderSystem + 1

// auto run
func init() {
system.RegisterInit(initOrderApi, &initApi{})
system.RegisterInit(initOrderApi, new(initApi))
}

func (i initApi) InitializerName() string {
func (i *initApi) InitializerName() string {
return sysModel.SysApi{}.TableName()
}

Expand Down
4 changes: 2 additions & 2 deletions server/source/system/api_ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const initOrderApiIgnore = initOrderApi + 1

// auto run
func init() {
system.RegisterInit(initOrderApiIgnore, &initApiIgnore{})
system.RegisterInit(initOrderApiIgnore, new(initApiIgnore))
}

func (i initApiIgnore) InitializerName() string {
func (i *initApiIgnore) InitializerName() string {
return sysModel.SysIgnoreApi{}.TableName()
}

Expand Down
4 changes: 2 additions & 2 deletions server/source/system/authorities_menus.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func (i *initMenuAuthority) InitializeData(ctx context.Context) (next context.Co
if !ok {
return ctx, system.ErrMissingDBContext
}
authorities, ok := ctx.Value(initAuthority{}.InitializerName()).([]sysModel.SysAuthority)
authorities, ok := ctx.Value(new(initAuthority).InitializerName()).([]sysModel.SysAuthority)
if !ok {
return ctx, errors.Wrap(system.ErrMissingDependentContext, "创建 [菜单-权限] 关联失败, 未找到权限表初始化数据")
}
menus, ok := ctx.Value(initMenu{}.InitializerName()).([]sysModel.SysBaseMenu)
menus, ok := ctx.Value(new(initMenu).InitializerName()).([]sysModel.SysBaseMenu)
if !ok {
return next, errors.Wrap(errors.New(""), "创建 [菜单-权限] 关联失败, 未找到菜单表初始化数据")
}
Expand Down
4 changes: 2 additions & 2 deletions server/source/system/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type initAuthority struct{}

// auto run
func init() {
system.RegisterInit(initOrderAuthority, &initAuthority{})
system.RegisterInit(initOrderAuthority, new(initAuthority))
}

func (i *initAuthority) MigrateTable(ctx context.Context) (context.Context, error) {
Expand All @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions server/source/system/casbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type initCasbin struct{}

// auto run
func init() {
system.RegisterInit(initOrderCasbin, &initCasbin{})
system.RegisterInit(initOrderCasbin, new(initCasbin))
}

func (i *initCasbin) MigrateTable(ctx context.Context) (context.Context, error) {
Expand All @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions server/source/system/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type initDict struct{}

// auto run
func init() {
system.RegisterInit(initOrderDict, &initDict{})
system.RegisterInit(initOrderDict, new(initDict))
}

func (i *initDict) MigrateTable(ctx context.Context) (context.Context, error) {
Expand All @@ -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()
}

Expand Down
6 changes: 3 additions & 3 deletions server/source/system/dictionary_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type initDictDetail struct{}

// auto run
func init() {
system.RegisterInit(initOrderDictDetail, &initDictDetail{})
system.RegisterInit(initOrderDictDetail, new(initDictDetail))
}

func (i *initDictDetail) MigrateTable(ctx context.Context) (context.Context, error) {
Expand All @@ -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()
}

Expand All @@ -43,7 +43,7 @@ func (i *initDictDetail) InitializeData(ctx context.Context) (context.Context, e
if !ok {
return ctx, system.ErrMissingDBContext
}
dicts, ok := ctx.Value(initDict{}.InitializerName()).([]sysModel.SysDictionary)
dicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary)
if !ok {
return ctx, errors.Wrap(system.ErrMissingDependentContext,
fmt.Sprintf("未找到 %s 表初始化数据", sysModel.SysDictionary{}.TableName()))
Expand Down
4 changes: 2 additions & 2 deletions server/source/system/excel_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const initOrderExcelTemplate = initOrderDictDetail + 1

// auto run
func init() {
system.RegisterInit(initOrderExcelTemplate, &initExcelTemplate{})
system.RegisterInit(initOrderExcelTemplate, new(initExcelTemplate))
}

func (i initExcelTemplate) InitializerName() string {
func (i *initExcelTemplate) InitializerName() string {
return "sys_export_templates"
}

Expand Down
4 changes: 2 additions & 2 deletions server/source/system/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type initMenu struct{}

// auto run
func init() {
system.RegisterInit(initOrderMenu, &initMenu{})
system.RegisterInit(initOrderMenu, new(initMenu))
}

func (i initMenu) InitializerName() string {
func (i *initMenu) InitializerName() string {
return SysBaseMenu{}.TableName()
}

Expand Down
6 changes: 3 additions & 3 deletions server/source/system/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type initUser struct{}

// auto run
func init() {
system.RegisterInit(initOrderUser, &initUser{})
system.RegisterInit(initOrderUser, new(initUser))
}

func (i *initUser) MigrateTable(ctx context.Context) (context.Context, error) {
Expand All @@ -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()
}

Expand Down Expand Up @@ -79,7 +79,7 @@ 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)
authorityEntities, ok := ctx.Value(new(initAuthority).InitializerName()).([]sysModel.SysAuthority)
if !ok {
return next, errors.Wrap(system.ErrMissingDependentContext, "创建 [用户-权限] 关联失败, 未找到权限表初始化数据")
}
Expand Down

0 comments on commit 9fdbeb2

Please sign in to comment.