From 93ac2e70d24fc4db7b0517c1e8c931f85a094170 Mon Sep 17 00:00:00 2001
From: andywu1998 <1078539713@qq.com>
Date: Wed, 6 Mar 2024 23:38:17 +0800
Subject: [PATCH] =?UTF-8?q?feat(gin.Mode()):=20=E7=94=B1=E7=8E=AF=E5=A2=83?=
=?UTF-8?q?=E5=8F=98=E9=87=8F=E5=86=B3=E5=AE=9A=EF=BC=8C=E4=B8=8D=E5=86=8D?=
=?UTF-8?q?=E4=BE=9D=E8=B5=96=E4=BA=8E=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?=
=?UTF-8?q?system.Env=20(#1668)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(gin.Mode()): 由环境变量决定,不再依赖于配置文件system.Env
* feat(casbin):不需要判断是否是debug模式,都要附带参数
* feat(前端配置):去掉环境之的配置
---
server/config/system.go | 1 -
server/initialize/router.go | 8 +-----
server/middleware/casbin_rbac.go | 30 ++++++++++------------
web/src/view/systemTools/system/system.vue | 10 --------
4 files changed, 15 insertions(+), 34 deletions(-)
diff --git a/server/config/system.go b/server/config/system.go
index 647e1539b..398bf789b 100644
--- a/server/config/system.go
+++ b/server/config/system.go
@@ -1,7 +1,6 @@
package config
type System struct {
- Env string `mapstructure:"env" json:"env" yaml:"env"` // 环境值
DbType string `mapstructure:"db-type" json:"db-type" yaml:"db-type"` // 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql
OssType string `mapstructure:"oss-type" json:"oss-type" yaml:"oss-type"` // Oss类型
RouterPrefix string `mapstructure:"router-prefix" json:"router-prefix" yaml:"router-prefix"`
diff --git a/server/initialize/router.go b/server/initialize/router.go
index b635574f2..3b90889b4 100644
--- a/server/initialize/router.go
+++ b/server/initialize/router.go
@@ -33,15 +33,9 @@ func (fs justFilesFilesystem) Open(name string) (http.File, error) {
// 初始化总路由
func Routers() *gin.Engine {
-
- // 设置为发布模式
- if global.GVA_CONFIG.System.Env == "public" {
- gin.SetMode(gin.ReleaseMode) //DebugMode ReleaseMode TestMode
- }
-
Router := gin.New()
Router.Use(gin.Recovery())
- if global.GVA_CONFIG.System.Env != "public" {
+ if gin.Mode() == gin.DebugMode {
Router.Use(gin.Logger())
}
diff --git a/server/middleware/casbin_rbac.go b/server/middleware/casbin_rbac.go
index 7994db1ef..a1ca4c2b7 100644
--- a/server/middleware/casbin_rbac.go
+++ b/server/middleware/casbin_rbac.go
@@ -16,22 +16,20 @@ var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService
// CasbinHandler 拦截器
func CasbinHandler() gin.HandlerFunc {
return func(c *gin.Context) {
- if global.GVA_CONFIG.System.Env != "develop" {
- waitUse, _ := utils.GetClaims(c)
- //获取请求的PATH
- path := c.Request.URL.Path
- obj := strings.TrimPrefix(path, global.GVA_CONFIG.System.RouterPrefix)
- // 获取请求方法
- act := c.Request.Method
- // 获取用户的角色
- sub := strconv.Itoa(int(waitUse.AuthorityId))
- e := casbinService.Casbin() // 判断策略中是否存在
- success, _ := e.Enforce(sub, obj, act)
- if !success {
- response.FailWithDetailed(gin.H{}, "权限不足", c)
- c.Abort()
- return
- }
+ waitUse, _ := utils.GetClaims(c)
+ //获取请求的PATH
+ path := c.Request.URL.Path
+ obj := strings.TrimPrefix(path, global.GVA_CONFIG.System.RouterPrefix)
+ // 获取请求方法
+ act := c.Request.Method
+ // 获取用户的角色
+ sub := strconv.Itoa(int(waitUse.AuthorityId))
+ e := casbinService.Casbin() // 判断策略中是否存在
+ success, _ := e.Enforce(sub, obj, act)
+ if !success {
+ response.FailWithDetailed(gin.H{}, "权限不足", c)
+ c.Abort()
+ return
}
c.Next()
}
diff --git a/web/src/view/systemTools/system/system.vue b/web/src/view/systemTools/system/system.vue
index 642164ac3..d6db6bb01 100644
--- a/web/src/view/systemTools/system/system.vue
+++ b/web/src/view/systemTools/system/system.vue
@@ -11,16 +11,6 @@
title="系统配置"
name="1"
>
-
-
-
-
-
-
-