-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
增加命令行设置配置参数 #6
base: master
Are you sure you want to change the base?
增加命令行设置配置参数 #6
Conversation
@shafreeck 看一下这种实现方式是否可行。 |
configo.go
Outdated
@@ -272,6 +272,9 @@ func Unmarshal(data []byte, v interface{}) error { | |||
if err := applyDefault(reflect.ValueOf(v), false); err != nil { | |||
return err | |||
} | |||
|
|||
// apply flag param | |||
ApplyFlags(v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉放到这里,或默认启用flag不太合适,比如我只想解析toml,不想使用flag呢?
是不是考虑将Unmarshal, ApplyFlags, ApplyEnvs 当做独立的函数,然后通过更上层的函数合并起来?
flags.go
Outdated
./cmd -array="[\"a1\", \"a2\"]" | ||
*/ | ||
|
||
var flagMap map[string]struct{} = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flagMap 能否省掉? 比如直接查询FlagSet?
最好翻译为英文, 可以寻求下@xuehuaying 的协助 |
这个pr需要我帮助吗? |
先等确认版本的,确认之后再翻译,谢谢! |
通过在
flag.Parse()
之前调用configo.AddFlags()
方法,即可实现将配置文件中的参数添加到flag中,从而可以通过命令行设置配置文件参数。