Skip to content

Commit

Permalink
feat(gin.Mode()): 由环境变量决定,不再依赖于配置文件system.Env
Browse files Browse the repository at this point in the history
  • Loading branch information
andywu1998 committed Mar 6, 2024
1 parent d360049 commit d2f0f8f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
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
2 changes: 1 addition & 1 deletion server/middleware/casbin_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService
// CasbinHandler 拦截器
func CasbinHandler() gin.HandlerFunc {
return func(c *gin.Context) {
if global.GVA_CONFIG.System.Env != "develop" {
if gin.Mode() != gin.DebugMode {
waitUse, _ := utils.GetClaims(c)
//获取请求的PATH
path := c.Request.URL.Path
Expand Down

0 comments on commit d2f0f8f

Please sign in to comment.