-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: Support string duration format in config files #408
Conversation
So if I change for example in ETCD cn-infra/db/keyval/etcd/config.go Line 34 in 9bb0e39
to be not dialTimeout := defaultDialTimeout
- if yc.DialTimeout != 0 {
- dialTimeout = yc.DialTimeout
+ if yc.DialTimeout.Duration != 0 {
+ dialTimeout = yc.DialTimeout.Duration
} For now, I didn't find better solution. @ondrej-fabry please advise |
config/parser.go
Outdated
dc := &mapstructure.DecoderConfig{ | ||
DecodeHook: func(in, out reflect.Type, data interface{}) (interface{}, error) { | ||
// Only intended to help with cases when string must be set to `time.Duration` | ||
if in.Kind() != reflect.String || out.Name() != "Duration" { |
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.
Checking by type name is not very certain as it will match for other types named Duration
.
However you can compare types directly, because the reflect.Type
values are comparable:
reflect.TypeOf(out) == reflect.TypeOf(time.Duration(0))
Issue #399
This PR allows setting duration fields, which have
time.Duration
type, in config files not only in nanoseconds:but as a string too