From 543ca2df8ccbfee8e4dc25e16382d8db8db0e429 Mon Sep 17 00:00:00 2001 From: "{1570967070@qq.com}" <1570967070@qq.com> Date: Mon, 15 Jan 2024 17:55:44 +0800 Subject: [PATCH 1/6] doc: up swag version to adapter LeftDelim/RightDelim --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index bdbb0a1d..a4fc4612 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/swaggo/files v1.0.1 github.com/swaggo/gin-swagger v1.6.0 - github.com/swaggo/swag v1.8.12 + github.com/swaggo/swag v1.16.2 github.com/urfave/cli/v2 v2.25.1 go.uber.org/zap v1.24.0 golang.org/x/crypto v0.8.0 diff --git a/go.sum b/go.sum index b1ad29cc..2f3777e2 100644 --- a/go.sum +++ b/go.sum @@ -352,8 +352,8 @@ github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M= github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= -github.com/swaggo/swag v1.8.12 h1:pctzkNPu0AlQP2royqX3apjKCQonAnf7KGoxeO4y64w= -github.com/swaggo/swag v1.8.12/go.mod h1:lNfm6Gg+oAq3zRJQNEMBE66LIJKM44mxFqhEEgy2its= +github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04= +github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E= github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= From 730505f5411ba03210534bc43f5fc21c1a3a2fb2 Mon Sep 17 00:00:00 2001 From: "{1570967070@qq.com}" <1570967070@qq.com> Date: Mon, 15 Jan 2024 22:56:21 +0800 Subject: [PATCH 2/6] doc: fix IDE warning --- cmd/start.go | 1 + cmd/stop.go | 2 +- cmd/version.go | 2 +- internal/config/parse.go | 2 +- internal/mods/mods.go | 2 +- internal/mods/rbac/api/login.api.go | 9 +++++++++ internal/mods/rbac/api/menu.api.go | 5 +++++ internal/mods/rbac/api/role.api.go | 5 +++++ internal/mods/rbac/api/user.api.go | 6 ++++++ internal/mods/rbac/biz/login.biz.go | 12 ++++++------ internal/mods/rbac/casbin.go | 2 +- internal/mods/rbac/dal/menu.dal.go | 12 ++++++------ internal/mods/rbac/dal/menu_resource.dal.go | 8 ++++---- internal/mods/rbac/dal/role.dal.go | 4 ++-- internal/mods/rbac/dal/role_menu.dal.go | 10 +++++----- internal/mods/rbac/dal/user.dal.go | 4 ++-- internal/mods/rbac/dal/user_role.dal.go | 6 +++--- internal/mods/rbac/schema/menu.go | 12 ++++++------ internal/mods/rbac/schema/menu_resource.go | 14 +++++++------- internal/mods/rbac/schema/role.go | 12 ++++++------ internal/mods/rbac/schema/role_menu.go | 14 +++++++------- internal/mods/rbac/schema/user.go | 14 +++++++------- internal/mods/rbac/schema/user_role.go | 14 +++++++------- internal/mods/rbac/wire.go | 2 +- internal/mods/sys/api/logger.api.go | 1 + internal/mods/sys/dal/logger.dal.go | 2 +- internal/mods/sys/schema/logger.go | 8 ++++---- internal/swagger/docs.go | 4 +++- internal/wirex/injector.go | 4 ++-- main.go | 2 +- pkg/cachex/badger.go | 2 +- pkg/cachex/redis.go | 6 +++--- pkg/crypto/aes/aes.go | 2 +- pkg/crypto/hash/hash.go | 12 ++++++------ pkg/crypto/rand/rand.go | 4 ++-- pkg/errors/errors.go | 6 +++--- pkg/jwtx/jwt.go | 8 ++++---- pkg/logging/gorm.go | 2 +- pkg/logging/hook.go | 10 +++++----- pkg/mail/mail.go | 8 ++++---- pkg/middleware/cors.go | 2 +- pkg/middleware/logger.go | 2 +- pkg/oss/oss.go | 2 +- pkg/util/context.go | 2 +- pkg/util/gin.go | 12 ++++++------ pkg/util/id.go | 4 ++-- 46 files changed, 154 insertions(+), 125 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index ce1b0857..3c987684 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -13,6 +13,7 @@ import ( "github.com/urfave/cli/v2" ) +// StartCmd // The function defines a CLI command to start a server with various flags and options, including the // ability to run as a daemon. func StartCmd() *cli.Command { diff --git a/cmd/stop.go b/cmd/stop.go index 866b2363..fd0070cd 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -8,7 +8,7 @@ import ( "github.com/urfave/cli/v2" ) -// The function defines a CLI command to stop a server by reading a lock file, killing the process with +// StopCmd The function defines a CLI command to stop a server by reading a lock file, killing the process with // the corresponding PID, and removing the lock file. func StopCmd() *cli.Command { return &cli.Command{ diff --git a/cmd/version.go b/cmd/version.go index 605715b0..c13a4843 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/urfave/cli/v2" ) -// This function creates a CLI command that prints the version number. +// VersionCmd This function creates a CLI command that prints the version number. func VersionCmd(v string) *cli.Command { return &cli.Command{ Name: "version", diff --git a/internal/config/parse.go b/internal/config/parse.go index 8754111d..7e9268e3 100644 --- a/internal/config/parse.go +++ b/internal/config/parse.go @@ -25,7 +25,7 @@ func MustLoad(dir string, names ...string) { }) } -// Loads configuration files in various formats from a directory and parses them into +// Load configuration files in various formats from a directory and parses them into // a struct. func Load(dir string, names ...string) error { // Set default values diff --git a/internal/mods/mods.go b/internal/mods/mods.go index 7b367afc..5f02bd3f 100644 --- a/internal/mods/mods.go +++ b/internal/mods/mods.go @@ -13,7 +13,7 @@ const ( apiPrefix = "/api/" ) -// Collection of wire providers +// Set Collection of wire providers var Set = wire.NewSet( wire.Struct(new(Mods), "*"), rbac.Set, diff --git a/internal/mods/rbac/api/login.api.go b/internal/mods/rbac/api/login.api.go index 3e917377..8f5c332a 100644 --- a/internal/mods/rbac/api/login.api.go +++ b/internal/mods/rbac/api/login.api.go @@ -11,6 +11,7 @@ type Login struct { LoginBIZ *biz.Login } +// GetCaptcha // @Tags LoginAPI // @Summary Get captcha ID // @Success 200 {object} util.ResponseResult{data=schema.Captcha} @@ -25,6 +26,7 @@ func (a *Login) GetCaptcha(c *gin.Context) { util.ResSuccess(c, data) } +// ResponseCaptcha // @Tags LoginAPI // @Summary Response captcha image // @Param id query string true "Captcha ID" @@ -41,6 +43,7 @@ func (a *Login) ResponseCaptcha(c *gin.Context) { } } +// Login // @Tags LoginAPI // @Summary Login system with username and password // @Param body body schema.LoginForm true "Request body" @@ -64,6 +67,7 @@ func (a *Login) Login(c *gin.Context) { util.ResSuccess(c, data) } +// Logout // @Tags LoginAPI // @Security ApiKeyAuth // @Summary Logout system @@ -80,6 +84,7 @@ func (a *Login) Logout(c *gin.Context) { util.ResOK(c) } +// RefreshToken // @Tags LoginAPI // @Security ApiKeyAuth // @Summary Refresh current access token @@ -97,6 +102,7 @@ func (a *Login) RefreshToken(c *gin.Context) { util.ResSuccess(c, data) } +// GetUserInfo // @Tags LoginAPI // @Security ApiKeyAuth // @Summary Get current user info @@ -114,6 +120,7 @@ func (a *Login) GetUserInfo(c *gin.Context) { util.ResSuccess(c, data) } +// UpdatePassword // @Tags LoginAPI // @Security ApiKeyAuth // @Summary Change current user password @@ -139,6 +146,7 @@ func (a *Login) UpdatePassword(c *gin.Context) { util.ResOK(c) } +// QueryMenus // @Tags LoginAPI // @Security ApiKeyAuth // @Summary Query current user menus based on the current user role @@ -156,6 +164,7 @@ func (a *Login) QueryMenus(c *gin.Context) { util.ResSuccess(c, data) } +// UpdateUser // @Tags LoginAPI // @Security ApiKeyAuth // @Summary Update current user info diff --git a/internal/mods/rbac/api/menu.api.go b/internal/mods/rbac/api/menu.api.go index 7f4f5871..0dc0f394 100644 --- a/internal/mods/rbac/api/menu.api.go +++ b/internal/mods/rbac/api/menu.api.go @@ -12,6 +12,7 @@ type Menu struct { MenuBIZ *biz.Menu } +// Query // @Tags MenuAPI // @Security ApiKeyAuth // @Summary Query menu tree data @@ -38,6 +39,7 @@ func (a *Menu) Query(c *gin.Context) { util.ResPage(c, result.Data, result.PageResult) } +// Get // @Tags MenuAPI // @Security ApiKeyAuth // @Summary Get menu record by ID @@ -56,6 +58,7 @@ func (a *Menu) Get(c *gin.Context) { util.ResSuccess(c, item) } +// Create // @Tags MenuAPI // @Security ApiKeyAuth // @Summary Create menu record @@ -84,6 +87,7 @@ func (a *Menu) Create(c *gin.Context) { util.ResSuccess(c, result) } +// Update // @Tags MenuAPI // @Security ApiKeyAuth // @Summary Update menu record by ID @@ -113,6 +117,7 @@ func (a *Menu) Update(c *gin.Context) { util.ResOK(c) } +// Delete // @Tags MenuAPI // @Security ApiKeyAuth // @Summary Delete menu record by ID diff --git a/internal/mods/rbac/api/role.api.go b/internal/mods/rbac/api/role.api.go index 7afca9b6..d7a06990 100644 --- a/internal/mods/rbac/api/role.api.go +++ b/internal/mods/rbac/api/role.api.go @@ -12,6 +12,7 @@ type Role struct { RoleBIZ *biz.Role } +// Query // @Tags RoleAPI // @Security ApiKeyAuth // @Summary Query role list @@ -39,6 +40,7 @@ func (a *Role) Query(c *gin.Context) { util.ResPage(c, result.Data, result.PageResult) } +// Get // @Tags RoleAPI // @Security ApiKeyAuth // @Summary Get role record by ID @@ -57,6 +59,7 @@ func (a *Role) Get(c *gin.Context) { util.ResSuccess(c, item) } +// Create // @Tags RoleAPI // @Security ApiKeyAuth // @Summary Create role record @@ -85,6 +88,7 @@ func (a *Role) Create(c *gin.Context) { util.ResSuccess(c, result) } +// Update // @Tags RoleAPI // @Security ApiKeyAuth // @Summary Update role record by ID @@ -114,6 +118,7 @@ func (a *Role) Update(c *gin.Context) { util.ResOK(c) } +// Delete // @Tags RoleAPI // @Security ApiKeyAuth // @Summary Delete role record by ID diff --git a/internal/mods/rbac/api/user.api.go b/internal/mods/rbac/api/user.api.go index 6be8630f..398008c6 100644 --- a/internal/mods/rbac/api/user.api.go +++ b/internal/mods/rbac/api/user.api.go @@ -12,6 +12,7 @@ type User struct { UserBIZ *biz.User } +// Query // @Tags UserAPI // @Security ApiKeyAuth // @Summary Query user list @@ -40,6 +41,7 @@ func (a *User) Query(c *gin.Context) { util.ResPage(c, result.Data, result.PageResult) } +// Get // @Tags UserAPI // @Security ApiKeyAuth // @Summary Get user record by ID @@ -58,6 +60,7 @@ func (a *User) Get(c *gin.Context) { util.ResSuccess(c, item) } +// Create // @Tags UserAPI // @Security ApiKeyAuth // @Summary Create user record @@ -86,6 +89,7 @@ func (a *User) Create(c *gin.Context) { util.ResSuccess(c, result) } +// Update // @Tags UserAPI // @Security ApiKeyAuth // @Summary Update user record by ID @@ -115,6 +119,7 @@ func (a *User) Update(c *gin.Context) { util.ResOK(c) } +// Delete // @Tags UserAPI // @Security ApiKeyAuth // @Summary Delete user record by ID @@ -133,6 +138,7 @@ func (a *User) Delete(c *gin.Context) { util.ResOK(c) } +// ResetPassword // @Tags UserAPI // @Security ApiKeyAuth // @Summary Reset user password by ID diff --git a/internal/mods/rbac/biz/login.biz.go b/internal/mods/rbac/biz/login.biz.go index 8c6857ea..b2813f29 100644 --- a/internal/mods/rbac/biz/login.biz.go +++ b/internal/mods/rbac/biz/login.biz.go @@ -92,7 +92,7 @@ func (a *Login) ParseUserID(c *gin.Context) (string, error) { return userID, nil } -// This function generates a new captcha ID and returns it as a `schema.Captcha` struct. The length of +// GetCaptcha This function generates a new captcha ID and returns it as a `schema.Captcha` struct. The length of // the captcha is determined by the `config.C.Util.Captcha.Length` configuration value. func (a *Login) GetCaptcha(ctx context.Context) (*schema.Captcha, error) { return &schema.Captcha{ @@ -100,7 +100,7 @@ func (a *Login) GetCaptcha(ctx context.Context) (*schema.Captcha, error) { }, nil } -// Response captcha image +// ResponseCaptcha Response captcha image func (a *Login) ResponseCaptcha(ctx context.Context, w http.ResponseWriter, id string, reload bool) error { if reload && !captcha.Reload(id) { return errors.NotFound("", "Captcha id not found") @@ -240,7 +240,7 @@ func (a *Login) Logout(ctx context.Context) error { return nil } -// Get user info +// GetUserInfo Get user info func (a *Login) GetUserInfo(ctx context.Context) (*schema.User, error) { if util.FromIsRootUser(ctx) { return &schema.User{ @@ -276,7 +276,7 @@ func (a *Login) GetUserInfo(ctx context.Context) (*schema.User, error) { return user, nil } -// Change login password +// UpdatePassword Change login password func (a *Login) UpdatePassword(ctx context.Context, updateItem *schema.UpdateLoginPassword) error { if util.FromIsRootUser(ctx) { return errors.BadRequest("", "Root user cannot change password") @@ -307,7 +307,7 @@ func (a *Login) UpdatePassword(ctx context.Context, updateItem *schema.UpdateLog return a.UserDAL.UpdatePasswordByID(ctx, userID, newPassword) } -// Query menus based on user permissions +// QueryMenus Query menus based on user permissions func (a *Login) QueryMenus(ctx context.Context) (schema.Menus, error) { menuQueryParams := schema.MenuQueryParam{ Status: schema.MenuStatusEnabled, @@ -352,7 +352,7 @@ func (a *Login) QueryMenus(ctx context.Context) (schema.Menus, error) { return menuResult.Data.ToTree(), nil } -// Update current user info +// UpdateUser Update current user info func (a *Login) UpdateUser(ctx context.Context, updateItem *schema.UpdateCurrentUser) error { if util.FromIsRootUser(ctx) { return errors.BadRequest("", "Root user cannot update") diff --git a/internal/mods/rbac/casbin.go b/internal/mods/rbac/casbin.go index ea5ce6f1..368c1131 100644 --- a/internal/mods/rbac/casbin.go +++ b/internal/mods/rbac/casbin.go @@ -22,7 +22,7 @@ import ( "go.uber.org/zap" ) -// Load rbac permissions to casbin +// Casbinx Load rbac permissions to casbin type Casbinx struct { enforcer *atomic.Value `wire:"-"` ticker *time.Ticker `wire:"-"` diff --git a/internal/mods/rbac/dal/menu.dal.go b/internal/mods/rbac/dal/menu.dal.go index 12d412ff..0d613619 100644 --- a/internal/mods/rbac/dal/menu.dal.go +++ b/internal/mods/rbac/dal/menu.dal.go @@ -9,7 +9,7 @@ import ( "gorm.io/gorm" ) -// Get menu storage instance +// GetMenuDB Get menu storage instance func GetMenuDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return util.GetDB(ctx, defDB).Model(new(schema.Menu)) } @@ -116,19 +116,19 @@ func (a *Menu) GetByNameAndParentID(ctx context.Context, name, parentID string, return item, nil } -// Checks if the specified menu exists in the database. +// Exists Checks if the specified menu exists in the database. func (a *Menu) Exists(ctx context.Context, id string) (bool, error) { ok, err := util.Exists(ctx, GetMenuDB(ctx, a.DB).Where("id=?", id)) return ok, errors.WithStack(err) } -// Checks if a menu with the specified `code` exists under the specified `parentID` in the database. +// ExistsCodeByParentID Checks if a menu with the specified `code` exists under the specified `parentID` in the database. func (a *Menu) ExistsCodeByParentID(ctx context.Context, code, parentID string) (bool, error) { ok, err := util.Exists(ctx, GetMenuDB(ctx, a.DB).Where("code=? AND parent_id=?", code, parentID)) return ok, errors.WithStack(err) } -// Checks if a menu with the specified `name` exists under the specified `parentID` in the database. +// ExistsNameByParentID Checks if a menu with the specified `name` exists under the specified `parentID` in the database. func (a *Menu) ExistsNameByParentID(ctx context.Context, name, parentID string) (bool, error) { ok, err := util.Exists(ctx, GetMenuDB(ctx, a.DB).Where("name=? AND parent_id=?", name, parentID)) return ok, errors.WithStack(err) @@ -152,13 +152,13 @@ func (a *Menu) Delete(ctx context.Context, id string) error { return errors.WithStack(result.Error) } -// Updates the parent path of the specified menu. +// UpdateParentPath Updates the parent path of the specified menu. func (a *Menu) UpdateParentPath(ctx context.Context, id, parentPath string) error { result := GetMenuDB(ctx, a.DB).Where("id=?", id).Update("parent_path", parentPath) return errors.WithStack(result.Error) } -// Updates the status of all menus whose parent path starts with the provided parent path. +// UpdateStatusByParentPath Updates the status of all menus whose parent path starts with the provided parent path. func (a *Menu) UpdateStatusByParentPath(ctx context.Context, parentPath, status string) error { result := GetMenuDB(ctx, a.DB).Where("parent_path like ?", parentPath+"%").Update("status", status) return errors.WithStack(result.Error) diff --git a/internal/mods/rbac/dal/menu_resource.dal.go b/internal/mods/rbac/dal/menu_resource.dal.go index e0f71c74..8baa8617 100644 --- a/internal/mods/rbac/dal/menu_resource.dal.go +++ b/internal/mods/rbac/dal/menu_resource.dal.go @@ -9,12 +9,12 @@ import ( "gorm.io/gorm" ) -// Get menu resource storage instance +// GetMenuResourceDB Get menu resource storage instance func GetMenuResourceDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return util.GetDB(ctx, defDB).Model(new(schema.MenuResource)) } -// Menu resource management for RBAC +// MenuResource Menu resource management for RBAC type MenuResource struct { DB *gorm.DB } @@ -64,7 +64,7 @@ func (a *MenuResource) Get(ctx context.Context, id string, opts ...schema.MenuRe return item, nil } -// Exist checks if the specified menu resource exists in the database. +// Exists Exist checks if the specified menu resource exists in the database. func (a *MenuResource) Exists(ctx context.Context, id string) (bool, error) { ok, err := util.Exists(ctx, GetMenuResourceDB(ctx, a.DB).Where("id=?", id)) return ok, errors.WithStack(err) @@ -94,7 +94,7 @@ func (a *MenuResource) Delete(ctx context.Context, id string) error { return errors.WithStack(result.Error) } -// Deletes the menu resource by menu id. +// DeleteByMenuID Deletes the menu resource by menu id. func (a *MenuResource) DeleteByMenuID(ctx context.Context, menuID string) error { result := GetMenuResourceDB(ctx, a.DB).Where("menu_id=?", menuID).Delete(new(schema.MenuResource)) return errors.WithStack(result.Error) diff --git a/internal/mods/rbac/dal/role.dal.go b/internal/mods/rbac/dal/role.dal.go index fcc5470a..410f0269 100644 --- a/internal/mods/rbac/dal/role.dal.go +++ b/internal/mods/rbac/dal/role.dal.go @@ -9,7 +9,7 @@ import ( "gorm.io/gorm" ) -// Get role storage instance +// GetRoleDB Get role storage instance func GetRoleDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return util.GetDB(ctx, defDB).Model(new(schema.Role)) } @@ -70,7 +70,7 @@ func (a *Role) Get(ctx context.Context, id string, opts ...schema.RoleQueryOptio return item, nil } -// Exist checks if the specified role exists in the database. +// Exists Exist checks if the specified role exists in the database. func (a *Role) Exists(ctx context.Context, id string) (bool, error) { ok, err := util.Exists(ctx, GetRoleDB(ctx, a.DB).Where("id=?", id)) return ok, errors.WithStack(err) diff --git a/internal/mods/rbac/dal/role_menu.dal.go b/internal/mods/rbac/dal/role_menu.dal.go index 4c338067..de798d08 100644 --- a/internal/mods/rbac/dal/role_menu.dal.go +++ b/internal/mods/rbac/dal/role_menu.dal.go @@ -9,12 +9,12 @@ import ( "gorm.io/gorm" ) -// Get role menu storage instance +// GetRoleMenuDB Get role menu storage instance func GetRoleMenuDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return util.GetDB(ctx, defDB).Model(new(schema.RoleMenu)) } -// Role permissions for RBAC +// RoleMenu Role permissions for RBAC type RoleMenu struct { DB *gorm.DB } @@ -61,7 +61,7 @@ func (a *RoleMenu) Get(ctx context.Context, id string, opts ...schema.RoleMenuQu return item, nil } -// Exist checks if the specified role menu exists in the database. +// Exists Exist checks if the specified role menu exists in the database. func (a *RoleMenu) Exists(ctx context.Context, id string) (bool, error) { ok, err := util.Exists(ctx, GetRoleMenuDB(ctx, a.DB).Where("id=?", id)) return ok, errors.WithStack(err) @@ -85,13 +85,13 @@ func (a *RoleMenu) Delete(ctx context.Context, id string) error { return errors.WithStack(result.Error) } -// Deletes role menus by role id. +// DeleteByRoleID Deletes role menus by role id. func (a *RoleMenu) DeleteByRoleID(ctx context.Context, roleID string) error { result := GetRoleMenuDB(ctx, a.DB).Where("role_id=?", roleID).Delete(new(schema.RoleMenu)) return errors.WithStack(result.Error) } -// Deletes role menus by menu id. +// DeleteByMenuID Deletes role menus by menu id. func (a *RoleMenu) DeleteByMenuID(ctx context.Context, menuID string) error { result := GetRoleMenuDB(ctx, a.DB).Where("menu_id=?", menuID).Delete(new(schema.RoleMenu)) return errors.WithStack(result.Error) diff --git a/internal/mods/rbac/dal/user.dal.go b/internal/mods/rbac/dal/user.dal.go index 1a7986b1..c56e72b0 100644 --- a/internal/mods/rbac/dal/user.dal.go +++ b/internal/mods/rbac/dal/user.dal.go @@ -9,7 +9,7 @@ import ( "gorm.io/gorm" ) -// Get user storage instance +// GetUserDB Get user storage instance func GetUserDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return util.GetDB(ctx, defDB).Model(new(schema.User)) } @@ -83,7 +83,7 @@ func (a *User) GetByUsername(ctx context.Context, username string, opts ...schem return item, nil } -// Exist checks if the specified user exists in the database. +// Exists Exist checks if the specified user exists in the database. func (a *User) Exists(ctx context.Context, id string) (bool, error) { ok, err := util.Exists(ctx, GetUserDB(ctx, a.DB).Where("id=?", id)) return ok, errors.WithStack(err) diff --git a/internal/mods/rbac/dal/user_role.dal.go b/internal/mods/rbac/dal/user_role.dal.go index e0a50632..071b0a06 100644 --- a/internal/mods/rbac/dal/user_role.dal.go +++ b/internal/mods/rbac/dal/user_role.dal.go @@ -10,12 +10,12 @@ import ( "gorm.io/gorm" ) -// Get user role storage instance +// GetUserRoleDB Get user role storage instance func GetUserRoleDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return util.GetDB(ctx, defDB).Model(new(schema.UserRole)) } -// User roles for RBAC +// UserRole User roles for RBAC type UserRole struct { DB *gorm.DB } @@ -73,7 +73,7 @@ func (a *UserRole) Get(ctx context.Context, id string, opts ...schema.UserRoleQu return item, nil } -// Exist checks if the specified user role exists in the database. +// Exists Exist checks if the specified user role exists in the database. func (a *UserRole) Exists(ctx context.Context, id string) (bool, error) { ok, err := util.Exists(ctx, GetUserRoleDB(ctx, a.DB).Where("id=?", id)) return ok, errors.WithStack(err) diff --git a/internal/mods/rbac/schema/menu.go b/internal/mods/rbac/schema/menu.go index b299bc8d..322590f5 100644 --- a/internal/mods/rbac/schema/menu.go +++ b/internal/mods/rbac/schema/menu.go @@ -45,7 +45,7 @@ func (a *Menu) TableName() string { return config.C.FormatTableName("menu") } -// Defining the query parameters for the `Menu` struct. +// MenuQueryParam Defining the query parameters for the `Menu` struct. type MenuQueryParam struct { util.PaginationParam CodePath string `form:"code"` // Code path (like xxx.xxx.xxx) @@ -59,18 +59,18 @@ type MenuQueryParam struct { RoleID string `form:"-"` // Role ID } -// Defining the query options for the `Menu` struct. +// MenuQueryOptions Defining the query options for the `Menu` struct. type MenuQueryOptions struct { util.QueryOptions } -// Defining the query result for the `Menu` struct. +// MenuQueryResult Defining the query result for the `Menu` struct. type MenuQueryResult struct { Data Menus PageResult *util.PaginationResult } -// Defining the slice of `Menu` struct. +// Menus Defining the slice of `Menu` struct. type Menus []*Menu func (a Menus) Len() int { @@ -140,7 +140,7 @@ func (a Menus) ToTree() Menus { return list } -// Defining the data structure for creating a `Menu` struct. +// MenuForm Defining the data structure for creating a `Menu` struct. type MenuForm struct { Code string `json:"code" binding:"required,max=32"` // Code of menu (unique for each level) Name string `json:"name" binding:"required,max=128"` // Display name of menu @@ -154,7 +154,7 @@ type MenuForm struct { Resources MenuResources `json:"resources"` // Resources of menu } -// A validation function for the `MenuForm` struct. +// Validate A validation function for the `MenuForm` struct. func (a *MenuForm) Validate() error { if v := a.Properties; v != "" { if !json.Valid([]byte(v)) { diff --git a/internal/mods/rbac/schema/menu_resource.go b/internal/mods/rbac/schema/menu_resource.go index dd21d4de..c5b9aeed 100644 --- a/internal/mods/rbac/schema/menu_resource.go +++ b/internal/mods/rbac/schema/menu_resource.go @@ -7,7 +7,7 @@ import ( "github.com/LyricTian/gin-admin/v10/pkg/util" ) -// Menu resource management for RBAC +// MenuResource Menu resource management for RBAC type MenuResource struct { ID string `json:"id" gorm:"size:20;primarykey"` // Unique ID MenuID string `json:"menu_id" gorm:"size:20;index"` // From Menu.ID @@ -21,32 +21,32 @@ func (a *MenuResource) TableName() string { return config.C.FormatTableName("menu_resource") } -// Defining the query parameters for the `MenuResource` struct. +// MenuResourceQueryParam Defining the query parameters for the `MenuResource` struct. type MenuResourceQueryParam struct { util.PaginationParam MenuID string `form:"-"` // From Menu.ID MenuIDs []string `form:"-"` // From Menu.ID } -// Defining the query options for the `MenuResource` struct. +// MenuResourceQueryOptions Defining the query options for the `MenuResource` struct. type MenuResourceQueryOptions struct { util.QueryOptions } -// Defining the query result for the `MenuResource` struct. +// MenuResourceQueryResult Defining the query result for the `MenuResource` struct. type MenuResourceQueryResult struct { Data MenuResources PageResult *util.PaginationResult } -// Defining the slice of `MenuResource` struct. +// MenuResources Defining the slice of `MenuResource` struct. type MenuResources []*MenuResource -// Defining the data structure for creating a `MenuResource` struct. +// MenuResourceForm Defining the data structure for creating a `MenuResource` struct. type MenuResourceForm struct { } -// A validation function for the `MenuResourceForm` struct. +// Validate A validation function for the `MenuResourceForm` struct. func (a *MenuResourceForm) Validate() error { return nil } diff --git a/internal/mods/rbac/schema/role.go b/internal/mods/rbac/schema/role.go index 59d15d86..f314978b 100644 --- a/internal/mods/rbac/schema/role.go +++ b/internal/mods/rbac/schema/role.go @@ -31,7 +31,7 @@ func (a *Role) TableName() string { return config.C.FormatTableName("role") } -// Defining the query parameters for the `Role` struct. +// RoleQueryParam Defining the query parameters for the `Role` struct. type RoleQueryParam struct { util.PaginationParam LikeName string `form:"name"` // Display name of role @@ -41,21 +41,21 @@ type RoleQueryParam struct { GtUpdatedAt *time.Time `form:"-"` // Update time is greater than } -// Defining the query options for the `Role` struct. +// RoleQueryOptions Defining the query options for the `Role` struct. type RoleQueryOptions struct { util.QueryOptions } -// Defining the query result for the `Role` struct. +// RoleQueryResult Defining the query result for the `Role` struct. type RoleQueryResult struct { Data Roles PageResult *util.PaginationResult } -// Defining the slice of `Role` struct. +// Roles Defining the slice of `Role` struct. type Roles []*Role -// Defining the data structure for creating a `Role` struct. +// RoleForm Defining the data structure for creating a `Role` struct. type RoleForm struct { Code string `json:"code" binding:"required,max=32"` // Code of role (unique) Name string `json:"name" binding:"required,max=128"` // Display name of role @@ -65,7 +65,7 @@ type RoleForm struct { Menus RoleMenus `json:"menus"` // Role menu list } -// A validation function for the `RoleForm` struct. +// Validate A validation function for the `RoleForm` struct. func (a *RoleForm) Validate() error { return nil } diff --git a/internal/mods/rbac/schema/role_menu.go b/internal/mods/rbac/schema/role_menu.go index 4933941b..7ee1f0f0 100644 --- a/internal/mods/rbac/schema/role_menu.go +++ b/internal/mods/rbac/schema/role_menu.go @@ -7,7 +7,7 @@ import ( "github.com/LyricTian/gin-admin/v10/pkg/util" ) -// Role permissions for RBAC +// RoleMenu Role permissions for RBAC type RoleMenu struct { ID string `json:"id" gorm:"size:20;primarykey"` // Unique ID RoleID string `json:"role_id" gorm:"size:20;index"` // From Role.ID @@ -20,31 +20,31 @@ func (a *RoleMenu) TableName() string { return config.C.FormatTableName("role_menu") } -// Defining the query parameters for the `RoleMenu` struct. +// RoleMenuQueryParam Defining the query parameters for the `RoleMenu` struct. type RoleMenuQueryParam struct { util.PaginationParam RoleID string `form:"-"` // From Role.ID } -// Defining the query options for the `RoleMenu` struct. +// RoleMenuQueryOptions Defining the query options for the `RoleMenu` struct. type RoleMenuQueryOptions struct { util.QueryOptions } -// Defining the query result for the `RoleMenu` struct. +// RoleMenuQueryResult Defining the query result for the `RoleMenu` struct. type RoleMenuQueryResult struct { Data RoleMenus PageResult *util.PaginationResult } -// Defining the slice of `RoleMenu` struct. +// RoleMenus Defining the slice of `RoleMenu` struct. type RoleMenus []*RoleMenu -// Defining the data structure for creating a `RoleMenu` struct. +// RoleMenuForm Defining the data structure for creating a `RoleMenu` struct. type RoleMenuForm struct { } -// A validation function for the `RoleMenuForm` struct. +// Validate A validation function for the `RoleMenuForm` struct. func (a *RoleMenuForm) Validate() error { return nil } diff --git a/internal/mods/rbac/schema/user.go b/internal/mods/rbac/schema/user.go index a4c2fac2..b0aa3445 100644 --- a/internal/mods/rbac/schema/user.go +++ b/internal/mods/rbac/schema/user.go @@ -34,7 +34,7 @@ func (a *User) TableName() string { return config.C.FormatTableName("user") } -// Defining the query parameters for the `User` struct. +// UserQueryParam Defining the query parameters for the `User` struct. type UserQueryParam struct { util.PaginationParam LikeUsername string `form:"username"` // Username for login @@ -42,18 +42,18 @@ type UserQueryParam struct { Status string `form:"status" binding:"oneof=activated freezed ''"` // Status of user (activated, freezed) } -// Defining the query options for the `User` struct. +// UserQueryOptions Defining the query options for the `User` struct. type UserQueryOptions struct { util.QueryOptions } -// Defining the query result for the `User` struct. +// UserQueryResult Defining the query result for the `User` struct. type UserQueryResult struct { Data Users PageResult *util.PaginationResult } -// Defining the slice of `User` struct. +// Users Defining the slice of `User` struct. type Users []*User func (a Users) ToIDs() []string { @@ -64,7 +64,7 @@ func (a Users) ToIDs() []string { return ids } -// Defining the data structure for creating a `User` struct. +// UserForm Defining the data structure for creating a `User` struct. type UserForm struct { Username string `json:"username" binding:"required,max=64"` // Username for login Name string `json:"name" binding:"required,max=64"` // Name of user @@ -76,7 +76,7 @@ type UserForm struct { Roles UserRoles `json:"roles" binding:"required"` // Roles of user } -// A validation function for the `UserForm` struct. +// Validate A validation function for the `UserForm` struct. func (a *UserForm) Validate() error { if a.Email != "" && validator.New().Var(a.Email, "email") != nil { return errors.BadRequest("", "Invalid email address") @@ -84,7 +84,7 @@ func (a *UserForm) Validate() error { return nil } -// Convert `UserForm` to `User` object. +// FillTo Convert `UserForm` to `User` object. func (a *UserForm) FillTo(user *User) error { user.Username = a.Username user.Name = a.Name diff --git a/internal/mods/rbac/schema/user_role.go b/internal/mods/rbac/schema/user_role.go index 2073a3e2..e5427bba 100644 --- a/internal/mods/rbac/schema/user_role.go +++ b/internal/mods/rbac/schema/user_role.go @@ -7,7 +7,7 @@ import ( "github.com/LyricTian/gin-admin/v10/pkg/util" ) -// User roles for RBAC +// UserRole User roles for RBAC type UserRole struct { ID string `json:"id" gorm:"size:20;primarykey"` // Unique ID UserID string `json:"user_id" gorm:"size:20;index"` // From User.ID @@ -21,7 +21,7 @@ func (a *UserRole) TableName() string { return config.C.FormatTableName("user_role") } -// Defining the query parameters for the `UserRole` struct. +// UserRoleQueryParam Defining the query parameters for the `UserRole` struct. type UserRoleQueryParam struct { util.PaginationParam InUserIDs []string `form:"-"` // From User.ID @@ -29,19 +29,19 @@ type UserRoleQueryParam struct { RoleID string `form:"-"` // From Role.ID } -// Defining the query options for the `UserRole` struct. +// UserRoleQueryOptions Defining the query options for the `UserRole` struct. type UserRoleQueryOptions struct { util.QueryOptions JoinRole bool // Join role table } -// Defining the query result for the `UserRole` struct. +// UserRoleQueryResult Defining the query result for the `UserRole` struct. type UserRoleQueryResult struct { Data UserRoles PageResult *util.PaginationResult } -// Defining the slice of `UserRole` struct. +// UserRoles Defining the slice of `UserRole` struct. type UserRoles []*UserRole func (a UserRoles) ToUserIDMap() map[string]UserRoles { @@ -60,11 +60,11 @@ func (a UserRoles) ToRoleIDs() []string { return ids } -// Defining the data structure for creating a `UserRole` struct. +// UserRoleForm Defining the data structure for creating a `UserRole` struct. type UserRoleForm struct { } -// A validation function for the `UserRoleForm` struct. +// Validate A validation function for the `UserRoleForm` struct. func (a *UserRoleForm) Validate() error { return nil } diff --git a/internal/mods/rbac/wire.go b/internal/mods/rbac/wire.go index 79581071..f470e3b1 100644 --- a/internal/mods/rbac/wire.go +++ b/internal/mods/rbac/wire.go @@ -7,7 +7,7 @@ import ( "github.com/google/wire" ) -// Collection of wire providers +// Set Collection of wire providers var Set = wire.NewSet( wire.Struct(new(RBAC), "*"), wire.Struct(new(Casbinx), "*"), diff --git a/internal/mods/sys/api/logger.api.go b/internal/mods/sys/api/logger.api.go index b1c9835c..c888a1b7 100644 --- a/internal/mods/sys/api/logger.api.go +++ b/internal/mods/sys/api/logger.api.go @@ -12,6 +12,7 @@ type Logger struct { LoggerBIZ *biz.Logger } +// Query // @Tags LoggerAPI // @Security ApiKeyAuth // @Summary Query logger list diff --git a/internal/mods/sys/dal/logger.dal.go b/internal/mods/sys/dal/logger.dal.go index d7a299e7..f7f38019 100644 --- a/internal/mods/sys/dal/logger.dal.go +++ b/internal/mods/sys/dal/logger.dal.go @@ -11,7 +11,7 @@ import ( "gorm.io/gorm" ) -// Get logger storage instance +// GetLoggerDB Get logger storage instance func GetLoggerDB(ctx context.Context, defDB *gorm.DB) *gorm.DB { return util.GetDB(ctx, defDB).Model(new(schema.Logger)) } diff --git a/internal/mods/sys/schema/logger.go b/internal/mods/sys/schema/logger.go index a3d6f323..499e09fd 100644 --- a/internal/mods/sys/schema/logger.go +++ b/internal/mods/sys/schema/logger.go @@ -26,7 +26,7 @@ func (a *Logger) TableName() string { return config.C.FormatTableName("logger") } -// Defining the query parameters for the `Logger` struct. +// LoggerQueryParam Defining the query parameters for the `Logger` struct. type LoggerQueryParam struct { util.PaginationParam Level string `form:"level"` // Log level @@ -38,16 +38,16 @@ type LoggerQueryParam struct { EndTime string `form:"endTime"` // End time } -// Defining the query options for the `Logger` struct. +// LoggerQueryOptions Defining the query options for the `Logger` struct. type LoggerQueryOptions struct { util.QueryOptions } -// Defining the query result for the `Logger` struct. +// LoggerQueryResult Defining the query result for the `Logger` struct. type LoggerQueryResult struct { Data Loggers PageResult *util.PaginationResult } -// Defining the slice of `Logger` struct. +// Loggers Defining the slice of `Logger` struct. type Loggers []*Logger diff --git a/internal/swagger/docs.go b/internal/swagger/docs.go index 7e0231b9..0758ad37 100644 --- a/internal/swagger/docs.go +++ b/internal/swagger/docs.go @@ -1,4 +1,4 @@ -// Code generated by swaggo/swag. DO NOT EDIT +// Package swagger Code generated by swaggo/swag. DO NOT EDIT package swagger import "github.com/swaggo/swag" @@ -2011,6 +2011,8 @@ var SwaggerInfo = &swag.Spec{ Description: "A lightweight, flexible, elegant and full-featured RBAC scaffolding based on GIN + GORM 2.0 + Casbin 2.0 + Wire DI.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/internal/wirex/injector.go b/internal/wirex/injector.go index bcc920b7..cf9ca2cc 100644 --- a/internal/wirex/injector.go +++ b/internal/wirex/injector.go @@ -20,7 +20,7 @@ type Injector struct { M *mods.Mods } -// It creates a new database connection, and returns a function that closes the connection +// InitDB It creates a new database connection, and returns a function that closes the connection func InitDB(ctx context.Context) (*gorm.DB, func(), error) { cfg := config.C.Storage.DB @@ -57,7 +57,7 @@ func InitDB(ctx context.Context) (*gorm.DB, func(), error) { }, nil } -// It returns a cachex.Cacher instance, a function to close the cache, and an error +// InitCacher It returns a cachex.Cacher instance, a function to close the cache, and an error func InitCacher(ctx context.Context) (cachex.Cacher, func(), error) { cfg := config.C.Storage.Cache diff --git a/main.go b/main.go index c7c5794e..c2c02ae4 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ import ( "github.com/urfave/cli/v2" ) -// Usage: go build -ldflags "-X main.VERSION=x.x.x" +// VERSION Usage: go build -ldflags "-X main.VERSION=x.x.x" var VERSION = "v10.0.2" // @title ginadmin diff --git a/pkg/cachex/badger.go b/pkg/cachex/badger.go index 26bfdc84..58ba9e3b 100644 --- a/pkg/cachex/badger.go +++ b/pkg/cachex/badger.go @@ -14,7 +14,7 @@ type BadgerConfig struct { Path string } -// Create badger-based cache +// NewBadgerCache Create badger-based cache func NewBadgerCache(cfg BadgerConfig, opts ...Option) Cacher { defaultOpts := &options{ Delimiter: defaultDelimiter, diff --git a/pkg/cachex/redis.go b/pkg/cachex/redis.go index 9660053c..50b0bcaa 100644 --- a/pkg/cachex/redis.go +++ b/pkg/cachex/redis.go @@ -16,7 +16,7 @@ type RedisConfig struct { DB int } -// Create redis-based cache +// NewRedisCache Create redis-based cache func NewRedisCache(cfg RedisConfig, opts ...Option) Cacher { cli := redis.NewClient(&redis.Options{ Addr: cfg.Addr, @@ -28,12 +28,12 @@ func NewRedisCache(cfg RedisConfig, opts ...Option) Cacher { return newRedisCache(cli, opts...) } -// Use redis client create cache +// NewRedisCacheWithClient Use redis client create cache func NewRedisCacheWithClient(cli *redis.Client, opts ...Option) Cacher { return newRedisCache(cli, opts...) } -// Use redis cluster client create cache +// NewRedisCacheWithClusterClient Use redis cluster client create cache func NewRedisCacheWithClusterClient(cli *redis.ClusterClient, opts ...Option) Cacher { return newRedisCache(cli, opts...) } diff --git a/pkg/crypto/aes/aes.go b/pkg/crypto/aes/aes.go index e9d21701..c372c1bc 100644 --- a/pkg/crypto/aes/aes.go +++ b/pkg/crypto/aes/aes.go @@ -8,7 +8,7 @@ import ( ) var ( - // Define aes secret key 2^5 + // SecretKey Define aes secret key 2^5 SecretKey = []byte("2985BCFDB5FE43129843DB59825F8647") ) diff --git a/pkg/crypto/hash/hash.go b/pkg/crypto/hash/hash.go index 0686d88d..68370376 100644 --- a/pkg/crypto/hash/hash.go +++ b/pkg/crypto/hash/hash.go @@ -8,31 +8,31 @@ import ( "golang.org/x/crypto/bcrypt" ) -// md5 hash +// MD5 md5 hash func MD5(b []byte) string { h := md5.New() _, _ = h.Write(b) return fmt.Sprintf("%x", h.Sum(nil)) } -// md5 hash +// MD5String md5 hash func MD5String(s string) string { return MD5([]byte(s)) } -// sha1 hash +// SHA1 sha1 hash func SHA1(b []byte) string { h := sha1.New() _, _ = h.Write(b) return fmt.Sprintf("%x", h.Sum(nil)) } -// sha1 hash +// SHA1String sha1 hash func SHA1String(s string) string { return SHA1([]byte(s)) } -// Use bcrypt generate password hash +// GeneratePassword Use bcrypt generate password hash func GeneratePassword(password string) (string, error) { b, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { @@ -41,7 +41,7 @@ func GeneratePassword(password string) (string, error) { return string(b), nil } -// Use bcrypt compare hash password and password +// CompareHashAndPassword Use bcrypt compare hash password and password func CompareHashAndPassword(hashedPassword, password string) error { return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) } diff --git a/pkg/crypto/rand/rand.go b/pkg/crypto/rand/rand.go index 2aeeeb19..8a79e2a4 100644 --- a/pkg/crypto/rand/rand.go +++ b/pkg/crypto/rand/rand.go @@ -23,9 +23,9 @@ var ( upperCaseLetters = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ) -// definition error +// ErrInvalidFlag definition error var ( - ErrInvalidFlag = errors.New("Invalid flag") + ErrInvalidFlag = errors.New("invalid flag") ) // Random generate a random string specifying the length of the random number diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index e6142f8c..97661014 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -1,5 +1,5 @@ // Package errors provides a way to return detailed information -// for an request error. The error is normally JSON encoded. +// for a request error. The error is normally JSON encoded. package errors import ( @@ -33,7 +33,7 @@ const ( DefaultRequestTimeoutID = "request_timeout" ) -// Customize the error structure for implementation errors.Error interface +// Error Customize the error structure for implementation errors.Error interface type Error struct { ID string `json:"id,omitempty"` Code int32 `json:"code,omitempty"` @@ -229,7 +229,7 @@ func FromError(err error) *Error { return Parse(err.Error()) } -// As finds the first error in err's chain that matches *Error +// As finds the first error in errs chain that matches *Error func As(err error) (*Error, bool) { if err == nil { return nil, false diff --git a/pkg/jwtx/jwt.go b/pkg/jwtx/jwt.go index 72cb5fe3..0bd77e27 100644 --- a/pkg/jwtx/jwt.go +++ b/pkg/jwtx/jwt.go @@ -9,11 +9,11 @@ import ( ) type Auther interface { - // Generate a JWT (JSON Web Token) with the provided subject. + // GenerateToken Generate a JWT (JSON Web Token) with the provided subject. GenerateToken(ctx context.Context, subject string) (TokenInfo, error) - // Invalidate a token by removing it from the token store. + // DestroyToken Invalidate a token by removing it from the token store. DestroyToken(ctx context.Context, accessToken string) error - // Parse the subject (or user identifier) from a given access token. + // ParseSubject Parse the subject (or user identifier) from a given access token. ParseSubject(ctx context.Context, accessToken string) (string, error) // Release any resources held by the JWTAuth instance. Release(ctx context.Context) error @@ -21,7 +21,7 @@ type Auther interface { const defaultKey = "CG24SDVP8OHPK395GB5G" -var ErrInvalidToken = errors.New("Invalid token") +var ErrInvalidToken = errors.New("invalid token") type options struct { signingMethod jwt.SigningMethod diff --git a/pkg/logging/gorm.go b/pkg/logging/gorm.go index c357ec6c..9d6323dd 100644 --- a/pkg/logging/gorm.go +++ b/pkg/logging/gorm.go @@ -31,7 +31,7 @@ func NewGormHook(db *gorm.DB) *GormHook { } } -// Gorm Logger Hook +// GormHook Gorm Logger Hook type GormHook struct { db *gorm.DB } diff --git a/pkg/logging/hook.go b/pkg/logging/hook.go index ced5c4f9..734c1d44 100644 --- a/pkg/logging/hook.go +++ b/pkg/logging/hook.go @@ -17,21 +17,21 @@ type hookOptions struct { extra map[string]string } -// Set the number of buffers +// SetHookMaxJobs Set the number of buffers func SetHookMaxJobs(maxJobs int) HookOption { return func(o *hookOptions) { o.maxJobs = maxJobs } } -// Set the number of worker threads +// SetHookMaxWorkers Set the number of worker threads func SetHookMaxWorkers(maxWorkers int) HookOption { return func(o *hookOptions) { o.maxWorkers = maxWorkers } } -// Set extended parameters +// SetHookExtra Set extended parameters func SetHookExtra(extra map[string]string) HookOption { return func(o *hookOptions) { o.extra = extra @@ -41,7 +41,7 @@ func SetHookExtra(extra map[string]string) HookOption { // HookOption a hook parameter options type HookOption func(*hookOptions) -// Creates a hook to be added to an instance of logger +// NewHook Creates a hook to be added to an instance of logger func NewHook(exec HookExecuter, opt ...HookOption) *Hook { opts := &hookOptions{ maxJobs: 1024, @@ -110,7 +110,7 @@ func (h *Hook) Write(p []byte) (int, error) { return len(p), nil } -// Waits for the log queue to be empty +// Flush Waits for the log queue to be empty func (h *Hook) Flush() { if atomic.LoadInt32(&h.closed) == 1 { return diff --git a/pkg/mail/mail.go b/pkg/mail/mail.go index 39f1f949..3fc5b314 100644 --- a/pkg/mail/mail.go +++ b/pkg/mail/mail.go @@ -13,24 +13,24 @@ var ( once sync.Once ) -// Set a global SMTP sender +// SetSender Set a global SMTP sender func SetSender(sender *SmtpSender) { once.Do(func() { globalSender = sender }) } -// Use smtp client send email with to/cc/bcc +// Send Use smtp client send email with to/cc/bcc func Send(ctx context.Context, to []string, cc []string, bcc []string, subject string, body string, file ...string) error { return globalSender.Send(ctx, to, cc, bcc, subject, body, file...) } -// Use smtp client send email, use to specify recipients +// SendTo Use smtp client send email, use to specify recipients func SendTo(ctx context.Context, to []string, subject string, body string, file ...string) error { return globalSender.SendTo(ctx, to, subject, body, file...) } -// A smtp email client +// SmtpSender A smtp email client type SmtpSender struct { SmtpHost string Port int diff --git a/pkg/middleware/cors.go b/pkg/middleware/cors.go index d97a35de..797c5bf3 100644 --- a/pkg/middleware/cors.go +++ b/pkg/middleware/cors.go @@ -17,7 +17,7 @@ type CORSConfig struct { // AllowMethods is a list of methods the client is allowed to use with // cross-domain requests. Default value is simple methods (GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS) AllowMethods []string - // AllowHeaders is list of non simple headers the client is allowed to use with + // AllowHeaders is list of non-simple headers the client is allowed to use with // cross-domain requests. AllowHeaders []string // AllowCredentials indicates whether the request can include user credentials like diff --git a/pkg/middleware/logger.go b/pkg/middleware/logger.go index f498cb19..3908553b 100644 --- a/pkg/middleware/logger.go +++ b/pkg/middleware/logger.go @@ -24,7 +24,7 @@ var DefaultLoggerConfig = LoggerConfig{ MaxOutputResponseBodyLen: 1024 * 1024, } -// Record detailed request logs for quick troubleshooting. +// Logger Record detailed request logs for quick troubleshooting. func Logger() gin.HandlerFunc { return LoggerWithConfig(DefaultLoggerConfig) } diff --git a/pkg/oss/oss.go b/pkg/oss/oss.go index e111e2b0..74820ee1 100644 --- a/pkg/oss/oss.go +++ b/pkg/oss/oss.go @@ -15,7 +15,7 @@ var ( once sync.Once ) -// Set the global oss client +// SetGlobal Set the global oss client func SetGlobal(h func() IClient) { once.Do(func() { Ins = h() diff --git a/pkg/util/context.go b/pkg/util/context.go index 6f55f54f..b2195ad3 100644 --- a/pkg/util/context.go +++ b/pkg/util/context.go @@ -83,7 +83,7 @@ func FromIsRootUser(ctx context.Context) bool { return v != nil && v.(bool) } -// Set user cache object +// UserCache Set user cache object type UserCache struct { RoleIDs []string `json:"rids"` } diff --git a/pkg/util/gin.go b/pkg/util/gin.go index 76f9f5a2..4fa9afa2 100644 --- a/pkg/util/gin.go +++ b/pkg/util/gin.go @@ -14,7 +14,7 @@ import ( "go.uber.org/zap" ) -// Get access token from header or query parameter +// GetToken Get access token from header or query parameter func GetToken(c *gin.Context) string { var token string auth := c.GetHeader("Authorization") @@ -33,7 +33,7 @@ func GetToken(c *gin.Context) string { return token } -// Get body data from context +// GetBodyData Get body data from context func GetBodyData(c *gin.Context) []byte { if v, ok := c.Get(ReqBodyKey); ok { if b, ok := v.([]byte); ok { @@ -43,7 +43,7 @@ func GetBodyData(c *gin.Context) []byte { return nil } -// Parse body json data to struct +// ParseJSON Parse body json data to struct func ParseJSON(c *gin.Context, obj interface{}) error { if err := c.ShouldBindJSON(obj); err != nil { return errors.BadRequest("", "Failed to parse json: %s", err.Error()) @@ -51,7 +51,7 @@ func ParseJSON(c *gin.Context, obj interface{}) error { return nil } -// Parse query parameter to struct +// ParseQuery Parse query parameter to struct func ParseQuery(c *gin.Context, obj interface{}) error { if err := c.ShouldBindQuery(obj); err != nil { return errors.BadRequest("", "Failed to parse query: %s", err.Error()) @@ -59,7 +59,7 @@ func ParseQuery(c *gin.Context, obj interface{}) error { return nil } -// Parse body form data to struct +// ParseForm Parse body form data to struct func ParseForm(c *gin.Context, obj interface{}) error { if err := c.ShouldBindWith(obj, binding.Form); err != nil { return errors.BadRequest("", "Failed to parse form: %s", err.Error()) @@ -67,7 +67,7 @@ func ParseForm(c *gin.Context, obj interface{}) error { return nil } -// Response json data with status code +// ResJSON Response json data with status code func ResJSON(c *gin.Context, status int, v interface{}) { buf, err := json.Marshal(v) if err != nil { diff --git a/pkg/util/id.go b/pkg/util/id.go index 48d7b6c0..e3708915 100644 --- a/pkg/util/id.go +++ b/pkg/util/id.go @@ -5,12 +5,12 @@ import ( "github.com/rs/xid" ) -// The function "NewXID" generates a new unique identifier (XID) and returns it as a string. +// NewXID The function "NewXID" generates a new unique identifier (XID) and returns it as a string. func NewXID() string { return xid.New().String() } -// The function generates a new UUID and panics if there is an error. +// MustNewUUID The function generates a new UUID and panics if there is an error. func MustNewUUID() string { v, err := uuid.NewRandom() if err != nil { From f74338eca6c5629bde7062e1ff6555ef703cfaa8 Mon Sep 17 00:00:00 2001 From: "{1570967070@qq.com}" <1570967070@qq.com> Date: Mon, 15 Jan 2024 23:01:32 +0800 Subject: [PATCH 3/6] doc: fix IDE warning --- cmd/start.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index 3c987684..1cc7b4a0 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -13,8 +13,7 @@ import ( "github.com/urfave/cli/v2" ) -// StartCmd -// The function defines a CLI command to start a server with various flags and options, including the +// StartCmd The function defines a CLI command to start a server with various flags and options, including the // ability to run as a daemon. func StartCmd() *cli.Command { return &cli.Command{ From 48588a3fbeed610ce08d08885f94a1f1fb3f6cd2 Mon Sep 17 00:00:00 2001 From: "{1570967070@qq.com}" <1570967070@qq.com> Date: Mon, 15 Jan 2024 23:32:47 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20=E4=BD=BF=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6DB.AutoMigrate=20=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/mods/rbac/main.go | 6 ++++-- internal/mods/sys/main.go | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/mods/rbac/main.go b/internal/mods/rbac/main.go index 69ad100d..54eefe77 100644 --- a/internal/mods/rbac/main.go +++ b/internal/mods/rbac/main.go @@ -34,8 +34,10 @@ func (a *RBAC) AutoMigrate(ctx context.Context) error { } func (a *RBAC) Init(ctx context.Context) error { - if err := a.AutoMigrate(ctx); err != nil { - return err + if config.C.Storage.DB.AutoMigrate { + if err := a.AutoMigrate(ctx); err != nil { + return err + } } if err := a.Casbinx.Load(ctx); err != nil { diff --git a/internal/mods/sys/main.go b/internal/mods/sys/main.go index dbc4969d..9dc3e687 100644 --- a/internal/mods/sys/main.go +++ b/internal/mods/sys/main.go @@ -2,6 +2,7 @@ package sys import ( "context" + "github.com/LyricTian/gin-admin/v10/internal/config" "github.com/LyricTian/gin-admin/v10/internal/mods/sys/api" "github.com/gin-gonic/gin" @@ -18,8 +19,10 @@ func (a *SYS) AutoMigrate(ctx context.Context) error { } func (a *SYS) Init(ctx context.Context) error { - if err := a.AutoMigrate(ctx); err != nil { - return err + if config.C.Storage.DB.AutoMigrate { + if err := a.AutoMigrate(ctx); err != nil { + return err + } } return nil } From bc99a5602ed07a435f022bd5ef14e8c5eacd658c Mon Sep 17 00:00:00 2001 From: "{1570967070@qq.com}" <1570967070@qq.com> Date: Tue, 16 Jan 2024 14:03:45 +0800 Subject: [PATCH 5/6] feat: add mf --- Makefile | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 348648fa..e4af3771 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,11 @@ build: @go build -ldflags "-w -s -X main.VERSION=$(RELEASE_TAG)" -o $(SERVER_BIN) # go install github.com/google/wire/cmd/wire@latest -wire: +wire: installCli @wire gen ./internal/wirex # go install github.com/swaggo/swag/cmd/swag@latest -swagger: +swagger: installCli @swag init --parseDependency --generalInfo ./main.go --output ./internal/swagger # https://github.com/OpenAPITools/openapi-generator @@ -45,4 +45,80 @@ serve-d: build ./$(SERVER_BIN) start $(START_ARGS) -d stop: - ./$(SERVER_BIN) stop \ No newline at end of file + ./$(SERVER_BIN) stop + +installCli: + go install github.com/gin-admin/gin-admin-cli/v10@latest + go install github.com/swaggo/swag/cmd/swag@latest + go install github.com/google/wire/cmd/wire@latest + +addStruct: installCli + @if [ ! -n "${m}" ]; then \ + echo "补充参数: m=[模块名]"; \ + exit 1; \ + fi; + @if [ ! -n "${s}" ]; then \ + echo "补充参数: s=[结构名(大驼峰命名)]"; \ + exit 1; \ + fi; + @if [ ! -n "${c}" ]; then \ + echo "补充参数: c=[结构注释]"; \ + exit 1; \ + fi; + gin-admin-cli gen -d . -m ${m} -s ${s} --structs-comment '${s} ${c}' + git add . + +rmStruct: installCli + @if [ ! -n "${m}" ]; then \ + echo "补充参数: m=[模块名]"; \ + exit 1; \ + fi; + @if [ ! -n "${s}" ]; then \ + echo "补充参数: s=[结构名]"; \ + exit 1; \ + fi; + gin-admin-cli rm -d . -m ${m} -s ${s} + +rmModule: + @if [ ! -n "${m}" ]; then \ + echo "补充参数: m=[模块名]"; \ + exit 1; \ + fi; + @if [ ! -d "internal/mods/${m}/api" ]; then \ + rm -rf internal/mods/${m}; \ + else \ + read -p "模块不为空,确认删除?[y/n]" input; \ + if [ "$${input}" = "y" ]; then \ + rm -rf internal/mods/${m}; \ + fi; \ + fi; + read -p "手动删除 internal/mods/mods.go 中的模块,然后回车执行 make wire:" + make wire; + +gitToDev: + @git add . && \ + git commit ; \ + git pull origin main && \ + current_branch=`git symbolic-ref --short -q HEAD` && \ + echo "当前分支:$${current_branch}" && \ + git push --set-upstream origin $${current_branch} && \ + git checkout dev && \ + git pull origin dev && \ + git merge $${current_branch} && \ + git push origin dev && \ + git checkout $${current_branch}; + + +gitToMain: + @git add . && \ + git commit ; \ + git pull origin main && \ + current_branch=`git symbolic-ref --short -q HEAD` && \ + echo "当前分支:$${current_branch}" && \ + git push --set-upstream origin $${current_branch} && \ + git checkout main && \ + git pull origin main && \ + git merge $${current_branch} && \ + git push origin main && \ + git checkout $${current_branch}; + From 44f2762828507173f3c2e0b52ca16fdcf2f40210 Mon Sep 17 00:00:00 2001 From: "{1570967070@qq.com}" <1570967070@qq.com> Date: Tue, 16 Jan 2024 14:37:51 +0800 Subject: [PATCH 6/6] feat: add mf --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e4af3771..279cb481 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ addStruct: installCli echo "补充参数: c=[结构注释]"; \ exit 1; \ fi; - gin-admin-cli gen -d . -m ${m} -s ${s} --structs-comment '${s} ${c}' + gin-admin-cli gen -d . -m ${m} --structs ${s} --structs-comment '${s} ${c}' git add . rmStruct: installCli @@ -77,7 +77,7 @@ rmStruct: installCli echo "补充参数: s=[结构名]"; \ exit 1; \ fi; - gin-admin-cli rm -d . -m ${m} -s ${s} + gin-admin-cli rm -d . -m ${m} --structs ${s} rmModule: @if [ ! -n "${m}" ]; then \