From a27e1d243c01865dbd145a78738662c6d4135799 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 17 Mar 2025 19:21:52 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.go | 2 +- src/config/config.default.yaml | 38 ++++++++--------------- src/config/config.local.yaml | 4 --- src/config/config.prod.yaml | 9 ------ src/framework/config/config.go | 4 +-- src/framework/middleware/crypto_api.go | 5 +-- src/framework/middleware/pre_authorize.go | 6 ++-- src/modules/common/service/account.go | 3 -- src/modules/common/service/commont.go | 4 +-- 9 files changed, 21 insertions(+), 54 deletions(-) diff --git a/src/app.go b/src/app.go index dbf5d269..9fa2fe10 100644 --- a/src/app.go +++ b/src/app.go @@ -36,7 +36,7 @@ func AppEngine() *gin.Engine { machine.Launch() // 读取服务配置 - app.ForwardedByClientIP = config.Get("server.proxy").(bool) + app.ForwardedByClientIP = true return app } diff --git a/src/config/config.default.yaml b/src/config/config.default.yaml index 00159330..8198d179 100644 --- a/src/config/config.default.yaml +++ b/src/config/config.default.yaml @@ -1,11 +1,11 @@ -# 应用服务配置 -server: - # 是否开启代理 - proxy: false - # 运行版本 standards/lite/tenants - runVersion: "standards" - # 运行模式 system/docker - runMode: "system" +# 运行版本 standard/lite/tenant +serverVersion: "standard" +# 运行模式 system/docker +serverMode: "system" +# 登录认证,默认打开 +serverLoginAuth: true +# 接口加密,默认关闭 +serverCryptoApi: false # 日志 logger: @@ -147,7 +147,7 @@ jwt: database: dataSource: # 默认数据库实例 - default: + standard: type: "mysql" host: "127.0.0.1" port: 3306 @@ -161,7 +161,7 @@ database: database: "" logging: false # 多个数据源时可以用这个指定默认的数据源 - defaultDataSourceName: "default" + defaultDataSourceName: "standard" # Redis 缓存数据 redis: @@ -183,21 +183,9 @@ aes: # 应用密钥 appKey: "E83dbfeb35BA4839232e2761b0FE5f32" -# 用户配置 -user: - # 登录认证,默认打开 - loginAuth: true - # 接口加密,默认打开 - cryptoApi: false - # 密码 - password: - # 密码最大错误次数 - maxRetryCount: 5 - # 密码锁定时间,单位分钟(默认10分钟) - lockTime: 10 - # 设定为系统管理员的用户ID - system: - - 1 +# 设定为系统管理员的用户ID +systemUser: + - 1 # char 字符验证码配置 charCaptcha: diff --git a/src/config/config.local.yaml b/src/config/config.local.yaml index c5c7b9d5..efe837a8 100644 --- a/src/config/config.local.yaml +++ b/src/config/config.local.yaml @@ -1,7 +1,3 @@ -# 应用服务配置 -server: - proxy: true - # 日志 logger: fileDir: "C:/var/log" diff --git a/src/config/config.prod.yaml b/src/config/config.prod.yaml index fbba0f9a..de321a4a 100644 --- a/src/config/config.prod.yaml +++ b/src/config/config.prod.yaml @@ -1,12 +1,3 @@ -# 应用服务配置 -server: - # 是否开启代理 - proxy: true - # 运行版本 standards/lite/tenants - runVersion: "standards" - # 运行模式 system/docker - runMode: "system" - # DB 数据源 database: dataSource: diff --git a/src/framework/config/config.go b/src/framework/config/config.go index 2d9c26cc..946b044c 100644 --- a/src/framework/config/config.go +++ b/src/framework/config/config.go @@ -166,7 +166,7 @@ func RunTime() time.Time { // Get 获取配置信息 // -// Get("server.proxy") +// Get("redis.defaultDataSourceName") func Get(key string) any { return conf.Get(key) } @@ -187,7 +187,7 @@ func IsSystemUser(userId int64) bool { return false } // 从配置中获取系统管理员ID列表 - arr := Get("user.system").([]any) + arr := Get("systemUser").([]any) for _, v := range arr { if fmt.Sprint(v) == fmt.Sprint(userId) { return true diff --git a/src/framework/middleware/crypto_api.go b/src/framework/middleware/crypto_api.go index 6c0ede4c..0e6b4ccf 100644 --- a/src/framework/middleware/crypto_api.go +++ b/src/framework/middleware/crypto_api.go @@ -26,10 +26,7 @@ import ( func CryptoApi(requestDecrypt, responseEncrypt bool) gin.HandlerFunc { return func(c *gin.Context) { // 登录认证,默认打开 - enable := true - if v := config.Get("user.cryptoApi"); v != nil && enable { - enable = v.(bool) - } + enable := parse.Boolean(config.Get("serverCryptoApi")) if !enable { c.Next() return diff --git a/src/framework/middleware/pre_authorize.go b/src/framework/middleware/pre_authorize.go index a19b87d6..5d069e86 100644 --- a/src/framework/middleware/pre_authorize.go +++ b/src/framework/middleware/pre_authorize.go @@ -9,6 +9,7 @@ import ( "be.ems/src/framework/reqctx" "be.ems/src/framework/resp" "be.ems/src/framework/token" + "be.ems/src/framework/utils/parse" "github.com/gin-gonic/gin" ) @@ -38,10 +39,7 @@ var URL_WHITE_LIST = []string{ func PreAuthorize(options map[string][]string) gin.HandlerFunc { return func(c *gin.Context) { // 登录认证,默认打开 - enable := true - if v := config.Get("user.loginAuth"); v != nil { - enable = v.(bool) - } + enable := parse.Boolean(config.Get("serverLoginAuth")) if !enable { loginUser, _ := reqctx.LoginUser(c) loginUser.UserId = 2 diff --git a/src/modules/common/service/account.go b/src/modules/common/service/account.go index 102bad66..28f94a31 100644 --- a/src/modules/common/service/account.go +++ b/src/modules/common/service/account.go @@ -127,9 +127,6 @@ func (s Account) passwordRetryCount(userName string) (string, int64, time.Durati // 验证登录次数和错误锁定时间 maxRetryCount := parse.Number(maxRetryCountStr) lockTime := parse.Number(lockTimeStr) - // 验证登录次数和错误锁定时间 - // maxRetryCount := config.Get("user.password.maxRetryCount").(int) - // lockTime := config.Get("user.password.lockTime").(int) // 验证缓存记录次数 retryKey := fmt.Sprintf("%s:%s", constants.CACHE_PWD_ERR_COUNT, userName) diff --git a/src/modules/common/service/commont.go b/src/modules/common/service/commont.go index abc1a10f..9f1a9b49 100644 --- a/src/modules/common/service/commont.go +++ b/src/modules/common/service/commont.go @@ -39,9 +39,9 @@ func (s *Commont) SystemConfigInfo() map[string]string { infoMap[constants.LAUNCH_BOOTLOADER] = "true" } // 用户登录认证 - infoMap["loginAuth"] = fmt.Sprint(config.Get("user.loginAuth")) + infoMap["loginAuth"] = fmt.Sprint(config.Get("serverLoginAuth")) // 用户接口加密 - infoMap["cryptoApi"] = fmt.Sprint(config.Get("user.cryptoApi")) + infoMap["cryptoApi"] = fmt.Sprint(config.Get("serverCryptoApi")) // 序列号 infoMap["serialNum"] = fmt.Sprint(config.Get("omc.sn")) // 获取LOGO类型