Skip to content

xtime 组件能否增加一个setlocation方法 拱外部修改 #76

@ayamzh

Description

@ayamzh

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模式或者接口来显示设置。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions