-
Notifications
You must be signed in to change notification settings - Fork 157
Open
Description
func init() {
timezone := etc.Get("etc.timezone", "Local").String()
if loc, err := time.LoadLocation(timezone); err != nil {
location = time.Local
} else {
location = loc
}
}
框架里面这种读取etc.的潜规则比较多 例如mode、pid 和 location mode还可以通过外部调用setmode来设置。 pid可以自己etc.set来改,由于go加载顺序问题 在main里修改timezone时,location已经确定了。。。建议尽量减少这种依赖env的潜规则,全部开方接口或者OPTION的方式来设置比较灵活。通常都用xconf包来管理配置,已经实现了动态加载,配置继承关系,env flag file的覆盖。我看咱们框架里还都是自己手动实现类似逻辑// 优先级: 配置文件 < 环境变量 < 运行参数 < mode.SetMode()
func init() {
mode := etc.Get(dueModeEtcName, DebugMode).String()
mode = env.Get(dueModeEnvName, mode).String()
mode = flag.String(dueModeArgName, mode)
SetMode(mode)
} 建议还是采用option模式或者接口来显示设置。
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels