Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gin.Mode()): 由环境变量决定,不再依赖于配置文件system.Env #1668

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion server/config/system.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down
8 changes: 1 addition & 7 deletions server/initialize/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
30 changes: 14 additions & 16 deletions server/middleware/casbin_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
10 changes: 0 additions & 10 deletions web/src/view/systemTools/system/system.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
title="系统配置"
name="1"
>
<el-form-item label="环境值">
<!-- <el-input v-model="config.system.env" />-->
<el-select
v-model="config.system.env"
style="width:100%"
>
<el-option value="public" />
<el-option value="develop" />
</el-select>
</el-form-item>
<el-form-item label="端口值">
<el-input v-model.number="config.system.addr" />
</el-form-item>
Expand Down
Loading