Skip to content

Commit

Permalink
added mode argument for etc file
Browse files Browse the repository at this point in the history
  • Loading branch information
dobyte committed Nov 6, 2024
1 parent 16f6087 commit d9cc711
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mode/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package mode

import (
"github.com/dobyte/due/v2/env"
"github.com/dobyte/due/v2/etc"
"github.com/dobyte/due/v2/flag"
)

const (
dueModeEtcName = "etc.mode"
dueModeArgName = "mode"
dueModeEnvName = "DUE_MODE"
)
Expand All @@ -21,9 +23,11 @@ const (

var dueMode string

// 优先级: env < etc < arg
func init() {
mode := flag.String(dueModeArgName, DebugMode)
mode = env.Get(dueModeEnvName, mode).String()
mode := env.Get(dueModeEnvName, DebugMode).String()
mode = etc.Get(dueModeEtcName, mode).String()
mode = flag.String(dueModeArgName, mode)
SetMode(mode)
}

Expand Down
2 changes: 2 additions & 0 deletions testdata/etc/etc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pid = "./run/cluster.pid"
# 统一时区设置。项目中的时间获取请使用xtime.Now()
timezone = "Local"
# 开发模式。支持模式:debug、test、release(模式优先级:环境变量 < 配置文件 < 运行参数)
mode = "debug"

# 任务池
[task]
Expand Down

0 comments on commit d9cc711

Please sign in to comment.