diff --git a/server/api/v1/system/auto_code_plugin.go b/server/api/v1/system/auto_code_plugin.go index 30029feb2c..a3b5cf1ea7 100644 --- a/server/api/v1/system/auto_code_plugin.go +++ b/server/api/v1/system/auto_code_plugin.go @@ -70,7 +70,7 @@ func (a *AutoCodePluginApi) Packaged(c *gin.Context) { response.OkWithMessage(fmt.Sprintf("打包成功,文件路径为:%s", zipPath), c) } -// Packaged +// InitMenu // @Tags AutoCodePlugin // @Summary 打包插件 // @Security ApiKeyAuth @@ -94,7 +94,7 @@ func (a *AutoCodePluginApi) InitMenu(c *gin.Context) { response.OkWithMessage("文件变更成功", c) } -// Packaged +// InitAPI // @Tags AutoCodePlugin // @Summary 打包插件 // @Security ApiKeyAuth diff --git a/server/api/v1/system/auto_code_template.go b/server/api/v1/system/auto_code_template.go index af63522b99..0f6041cfb4 100644 --- a/server/api/v1/system/auto_code_template.go +++ b/server/api/v1/system/auto_code_template.go @@ -82,7 +82,7 @@ func (a *AutoCodeTemplateApi) Create(c *gin.Context) { } } -// Create +// AddFunc // @Tags AddFunc // @Summary 增加方法 // @Security ApiKeyAuth diff --git a/server/initialize/ensure_tables.go b/server/initialize/ensure_tables.go index daa79f3532..3ef33490fc 100644 --- a/server/initialize/ensure_tables.go +++ b/server/initialize/ensure_tables.go @@ -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) { diff --git a/server/initialize/gorm_mssql.go b/server/initialize/gorm_mssql.go index 0ec25a7f56..e1478ea418 100644 --- a/server/initialize/gorm_mssql.go +++ b/server/initialize/gorm_mssql.go @@ -1,3 +1,5 @@ +package initialize + /* * @Author: 逆光飞翔 191180776@qq.com * @Date: 2022-12-08 17:25:49 @@ -6,7 +8,6 @@ * @FilePath: \server\initialize\gorm_mssql.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ -package initialize import ( "github.com/flipped-aurora/gin-vue-admin/server/config" @@ -44,8 +45,8 @@ func GormMssqlByConfig(m config.Mssql) *gorm.DB { return nil } mssqlConfig := sqlserver.Config{ - DSN: m.Dsn(), // DSN data source name - DefaultStringSize: 191, // string 类型字段的默认长度 + DSN: m.Dsn(), // DSN data source name + DefaultStringSize: 191, // string 类型字段的默认长度 } if db, err := gorm.Open(sqlserver.New(mssqlConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil { panic(err) diff --git a/server/model/system/request/sys_casbin.go b/server/model/system/request/sys_casbin.go index ef8c823cbe..3ca421276a 100644 --- a/server/model/system/request/sys_casbin.go +++ b/server/model/system/request/sys_casbin.go @@ -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"` diff --git a/server/model/system/request/sys_menu.go b/server/model/system/request/sys_menu.go index 2f5c7c46e1..275f037bc9 100644 --- a/server/model/system/request/sys_menu.go +++ b/server/model/system/request/sys_menu.go @@ -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 diff --git a/server/model/system/request/sys_user.go b/server/model/system/request/sys_user.go index 2e698d440c..45e478769d 100644 --- a/server/model/system/request/sys_user.go +++ b/server/model/system/request/sys_user.go @@ -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 diff --git a/server/service/example/exa_breakpoint_continue.go b/server/service/example/exa_breakpoint_continue.go index d0363bb5de..d2a85a3382 100644 --- a/server/service/example/exa_breakpoint_continue.go +++ b/server/service/example/exa_breakpoint_continue.go @@ -58,7 +58,7 @@ func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath st func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, filePath string) error { var chunks []example.ExaFileChunk var file example.ExaFile - err := global.GVA_DB.Where("file_md5 = ? ", fileMd5).First(&file). + err := global.GVA_DB.Where("file_md5 = ?", fileMd5).First(&file). Updates(map[string]interface{}{ "IsFinish": true, "file_path": filePath, diff --git a/server/service/system/sys_casbin.go b/server/service/system/sys_casbin.go index 32edc579e5..3a315efbaa 100644 --- a/server/service/system/sys_casbin.go +++ b/server/service/system/sys_casbin.go @@ -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 } diff --git a/server/source/example/file_upload_download.go b/server/source/example/file_upload_download.go index f39dcf2e51..0f6f7a7fad 100644 --- a/server/source/example/file_upload_download.go +++ b/server/source/example/file_upload_download.go @@ -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() } diff --git a/server/source/system/api.go b/server/source/system/api.go index 3dc211d00c..e657f34f5c 100644 --- a/server/source/system/api.go +++ b/server/source/system/api.go @@ -17,7 +17,7 @@ func init() { system.RegisterInit(initOrderApi, &initApi{}) } -func (i initApi) InitializerName() string { +func (i *initApi) InitializerName() string { return sysModel.SysApi{}.TableName() } diff --git a/server/source/system/api_ignore.go b/server/source/system/api_ignore.go index 284a1cc0c2..c0fab56500 100644 --- a/server/source/system/api_ignore.go +++ b/server/source/system/api_ignore.go @@ -17,7 +17,7 @@ func init() { system.RegisterInit(initOrderApiIgnore, &initApiIgnore{}) } -func (i initApiIgnore) InitializerName() string { +func (i *initApiIgnore) InitializerName() string { return sysModel.SysIgnoreApi{}.TableName() } diff --git a/server/source/system/authorities_menus.go b/server/source/system/authorities_menus.go index 1c9058b888..01fc801096 100644 --- a/server/source/system/authorities_menus.go +++ b/server/source/system/authorities_menus.go @@ -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(""), "创建 [菜单-权限] 关联失败, 未找到菜单表初始化数据") } diff --git a/server/source/system/authority.go b/server/source/system/authority.go index 0426f2a4fa..1157a19223 100644 --- a/server/source/system/authority.go +++ b/server/source/system/authority.go @@ -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() } diff --git a/server/source/system/casbin.go b/server/source/system/casbin.go index 5a9cdbec1a..c4528336df 100644 --- a/server/source/system/casbin.go +++ b/server/source/system/casbin.go @@ -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() } diff --git a/server/source/system/dictionary.go b/server/source/system/dictionary.go index 001496327f..a0cf8e0cb8 100644 --- a/server/source/system/dictionary.go +++ b/server/source/system/dictionary.go @@ -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() } diff --git a/server/source/system/dictionary_detail.go b/server/source/system/dictionary_detail.go index 3dea8b70ff..7f47939665 100644 --- a/server/source/system/dictionary_detail.go +++ b/server/source/system/dictionary_detail.go @@ -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())) diff --git a/server/source/system/excel_template.go b/server/source/system/excel_template.go index 00f3ed5f1a..20bf16dd4b 100644 --- a/server/source/system/excel_template.go +++ b/server/source/system/excel_template.go @@ -17,7 +17,7 @@ func init() { system.RegisterInit(initOrderExcelTemplate, &initExcelTemplate{}) } -func (i initExcelTemplate) InitializerName() string { +func (i *initExcelTemplate) InitializerName() string { return "sys_export_templates" } diff --git a/server/source/system/menu.go b/server/source/system/menu.go index 5b8ff0bdf7..30b177fde5 100644 --- a/server/source/system/menu.go +++ b/server/source/system/menu.go @@ -18,7 +18,7 @@ func init() { system.RegisterInit(initOrderMenu, &initMenu{}) } -func (i initMenu) InitializerName() string { +func (i *initMenu) InitializerName() string { return SysBaseMenu{}.TableName() } diff --git a/server/source/system/user.go b/server/source/system/user.go index b51c2fd44f..e54093b4ed 100644 --- a/server/source/system/user.go +++ b/server/source/system/user.go @@ -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, "创建 [用户-权限] 关联失败, 未找到权限表初始化数据") } diff --git a/server/utils/ast/ast.go b/server/utils/ast/ast.go index b6f85d6d03..1cdfa4c1e5 100644 --- a/server/utils/ast/ast.go +++ b/server/utils/ast/ast.go @@ -158,7 +158,7 @@ func CreateApiStructAst(apis []system.SysApi) *[]ast.Expr { return &apiElts } -// 检查是否存在Import +// CheckImport 检查是否存在Import func CheckImport(file *ast.File, importPath string) bool { for _, imp := range file.Imports { // Remove quotes around the import path diff --git a/server/utils/ast/ast_gorm.go b/server/utils/ast/ast_gorm.go index d9c1beb3ef..4340721fe5 100644 --- a/server/utils/ast/ast_gorm.go +++ b/server/utils/ast/ast_gorm.go @@ -10,7 +10,7 @@ import ( "os" ) -// 自动为 gorm.go 注册一个自动迁移 +// AddRegisterTablesAst 自动为 gorm.go 注册一个自动迁移 func AddRegisterTablesAst(path, funcName, pk, varName, dbName, model string) { modelPk := fmt.Sprintf("github.com/flipped-aurora/gin-vue-admin/server/model/%s", pk) src, err := os.ReadFile(path) @@ -147,7 +147,7 @@ func addAutoMigrate(astBody *ast.BlockStmt, dbname string, pk string, model stri } } -// 为automigrate增加实参 +// NeedAppendModel 为automigrate增加实参 func NeedAppendModel(callNode ast.Node, pk string, model string) bool { flag := true ast.Inspect(callNode, func(node ast.Node) bool { diff --git a/server/utils/fmt_plus.go b/server/utils/fmt_plus.go index 65f3e13253..6f34cb47c4 100644 --- a/server/utils/fmt_plus.go +++ b/server/utils/fmt_plus.go @@ -68,7 +68,7 @@ func MaheHump(s string) string { return strings.Join(words, "") } -// 随机字符串 +// RandomString 随机字符串 func RandomString(n int) string { var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") b := make([]rune, n) diff --git a/server/utils/jwt.go b/server/utils/jwt.go index c1298a870f..e8eb9721dc 100644 --- a/server/utils/jwt.go +++ b/server/utils/jwt.go @@ -43,7 +43,7 @@ func (j *JWT) CreateClaims(baseClaims request.BaseClaims) request.CustomClaims { return claims } -// 创建一个token +// CreateToken 创建一个token func (j *JWT) CreateToken(claims request.CustomClaims) (string, error) { token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) return token.SignedString(j.SigningKey) @@ -57,7 +57,7 @@ func (j *JWT) CreateTokenByOldToken(oldToken string, claims request.CustomClaims return v.(string), err } -// 解析 token +// ParseToken 解析 token func (j *JWT) ParseToken(tokenString string) (*request.CustomClaims, error) { token, err := jwt.ParseWithClaims(tokenString, &request.CustomClaims{}, func(token *jwt.Token) (i interface{}, e error) { return j.SigningKey, nil diff --git a/server/utils/timer/timed_task.go b/server/utils/timer/timed_task.go index 9f761436f0..06865d25d0 100644 --- a/server/utils/timer/timed_task.go +++ b/server/utils/timer/timed_task.go @@ -72,7 +72,7 @@ func (t *timer) AddTaskByFunc(cronName string, spec string, fun func(), taskName return id, err } -// AddTaskByFuncWithSeconds 通过函数的方法使用WithSeconds添加任务 +// AddTaskByFuncWithSecond 通过函数的方法使用WithSeconds添加任务 func (t *timer) AddTaskByFuncWithSecond(cronName string, spec string, fun func(), taskName string, option ...cron.Option) (cron.EntryID, error) { t.Lock() defer t.Unlock() @@ -186,7 +186,7 @@ func (t *timer) StopCron(cronName string) { } } -// Remove 从cronName 删除指定任务 +// RemoveTask 从cronName 删除指定任务 func (t *timer) RemoveTask(cronName string, id int) { t.Lock() defer t.Unlock()