Skip to content

Commit

Permalink
Merge pull request #1956 from bellingham07/main
Browse files Browse the repository at this point in the history
docs:调整部分代码注释以及代码格式
  • Loading branch information
pixelmaxQm authored Dec 8, 2024
2 parents 31cfdac + da72ee9 commit 19b174f
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 40 deletions.
4 changes: 2 additions & 2 deletions server/api/v1/system/auto_code_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -94,7 +94,7 @@ func (a *AutoCodePluginApi) InitMenu(c *gin.Context) {
response.OkWithMessage("文件变更成功", c)
}

// Packaged
// InitAPI
// @Tags AutoCodePlugin
// @Summary 打包插件
// @Security ApiKeyAuth
Expand Down
2 changes: 1 addition & 1 deletion server/api/v1/system/auto_code_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (a *AutoCodeTemplateApi) Create(c *gin.Context) {
}
}

// Create
// AddFunc
// @Tags AddFunc
// @Summary 增加方法
// @Security ApiKeyAuth
Expand Down
2 changes: 1 addition & 1 deletion server/initialize/ensure_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions server/initialize/gorm_mssql.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package initialize

/*
* @Author: 逆光飞翔 191180776@qq.com
* @Date: 2022-12-08 17:25:49
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/model/system/request/sys_casbin.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion server/model/system/request/sys_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions server/model/system/request/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ 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"` // 密码
Captcha string `json:"captcha"` // 验证码
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
Expand Down
2 changes: 1 addition & 1 deletion server/service/example/exa_breakpoint_continue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions server/service/system/sys_casbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
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
2 changes: 1 addition & 1 deletion server/source/system/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
system.RegisterInit(initOrderApi, &initApi{})
}

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

Expand Down
2 changes: 1 addition & 1 deletion server/source/system/api_ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
system.RegisterInit(initOrderApiIgnore, &initApiIgnore{})
}

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

Expand Down
8 changes: 5 additions & 3 deletions server/source/system/authorities_menus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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(""), "创建 [菜单-权限] 关联失败, 未找到菜单表初始化数据")
}
Expand Down
2 changes: 1 addition & 1 deletion server/source/system/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion server/source/system/casbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion server/source/system/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: 4 additions & 2 deletions server/source/system/dictionary_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,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()))
Expand Down
2 changes: 1 addition & 1 deletion server/source/system/excel_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
system.RegisterInit(initOrderExcelTemplate, &initExcelTemplate{})
}

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

Expand Down
2 changes: 1 addition & 1 deletion server/source/system/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
system.RegisterInit(initOrderMenu, &initMenu{})
}

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

Expand Down
5 changes: 3 additions & 2 deletions server/source/system/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,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, "创建 [用户-权限] 关联失败, 未找到权限表初始化数据")
}
Expand Down
2 changes: 1 addition & 1 deletion server/utils/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/utils/ast/ast_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/utils/fmt_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/utils/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/utils/timer/timed_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 19b174f

Please sign in to comment.