Skip to content

Commit

Permalink
altsrc: Parse durations from strings
Browse files Browse the repository at this point in the history
  • Loading branch information
cbranch committed Oct 26, 2017
1 parent b2bf3c5 commit d09ed35
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions altsrc/map_input_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,25 @@ func (fsm *MapInputSource) Duration(name string) (time.Duration, error) {
if exists {
otherValue, isType := otherGenericValue.(time.Duration)
if !isType {
return 0, incorrectTypeForFlagError(name, "duration", otherGenericValue)
otherStringValue, isType := otherGenericValue.(string)
parsedValue, err := time.ParseDuration(otherStringValue)
if !isType || err != nil {
return 0, incorrectTypeForFlagError(name, "duration", otherGenericValue)
}
return parsedValue, nil
}
return otherValue, nil
}
nestedGenericValue, exists := nestedVal(name, fsm.valueMap)
if exists {
otherValue, isType := nestedGenericValue.(time.Duration)
if !isType {
return 0, incorrectTypeForFlagError(name, "duration", nestedGenericValue)
otherStringValue, isType := otherGenericValue.(string)
parsedValue, err := time.ParseDuration(otherStringValue)
if !isType || err != nil {
return 0, incorrectTypeForFlagError(name, "duration", nestedGenericValue)
}
return parsedValue, nil
}
return otherValue, nil
}
Expand Down

0 comments on commit d09ed35

Please sign in to comment.