Skip to content

Commit

Permalink
配置文件,新增 运行模式 配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
gongcoder committed Mar 7, 2021
1 parent 48c5bf0 commit 44b5ed6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var (
SessionDrive string
SessionOption = make(map[string]interface{})
SessionDriveRedisConfig = make(map[string]interface{})
GinRunMode string
GinWriteLog bool
)

func ReadConfig() {
Expand Down Expand Up @@ -50,4 +52,9 @@ func ReadConfig() {
SessionDriveRedisConfig["password"], _ = config.GetConfig("session_driver_redis.password")
}

// 运行模式
GinRunMode, err = config.GetConfig("site.gin_run_mode")

// 是否记录运行日志
GinWriteLog, err = config.GetConfigToBool("site.gin_write_log")
}
9 changes: 7 additions & 2 deletions app/routers/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ func roleMiddleWare(role int) gin.HandlerFunc {
}

func InitRouter() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = ioutil.Discard
// 运行模式 release,debug,test
gin.SetMode(global.GinRunMode)

// 是否记录运行日志
if !global.GinWriteLog {
gin.DefaultWriter = ioutil.Discard
}

r := gin.Default()
r.Delims("[[", "]]")
Expand Down
9 changes: 8 additions & 1 deletion config/config.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# 站点配置
[site]
http_port = 8080
; web 端口号
http_port = "8080"

; gin 运行模式 release,debug,test
gin_run_mode = "release"

; 是否记录运行日志
gin_write_log = "1"

# 数据库配置
[mysql]
Expand Down

0 comments on commit 44b5ed6

Please sign in to comment.