-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
altsrc: Parse durations from strings #641
Conversation
👍 This seems reasonable to me, but do you mind adding a couple of tests for this behavior? cc/ @ChrisPRobinson since I think you still have the most context on |
@cbranch 👍, seems good other than tests. Reviewing my code I think what I should have done re #599 was just to add those types to the system. I also like what you have done for duration as well, accepting a string seems good there |
d09ed35
to
c265724
Compare
Finally got back to this one! |
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.
Thanks @cbranch !
One nitpick, but otherwise this looks good to me. Thanks for adding the tests. I agree that we can just focus on this type for now.
altsrc/map_input_source.go
Outdated
} | ||
|
||
return 0, nil | ||
} | ||
|
||
func castDuration(name string, value interface{}) (time.Duration, error) { | ||
otherValue, isType := value.(time.Duration) | ||
if !isType { |
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.
Nitpick, but can we do an early return like
if isType {
return otherValue, nil
}
...
Just to remove some of the nesting.
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.
Agreed, done.
c265724
to
01b6b91
Compare
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.
👍 thanks @cbranch !
Just waiting for build to finish (the failure looked like it might have been a CI flake). |
Fixed the build failure in #703. Apologies for the delay! |
Fixes part of #599.
I don't have a good idea (or the requirement) for fixing the other datatypes in that issue; presumably it should show the same leniency with exact types when parsing from weakly-typed data sources.