mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
agent: fix time.Duration parsing
The duration can be passed as a string, a float64 or a time.Duration and this patch handles this properly.
This commit is contained in:
parent
76e8ed07b0
commit
b5f8d6f9fd
@ -1426,18 +1426,16 @@ func FixupCheckType(raw interface{}) error {
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
if d, ok := v.(time.Duration); ok {
|
||||
return d, nil
|
||||
}
|
||||
s, ok := v.(string)
|
||||
if !ok {
|
||||
switch x := v.(type) {
|
||||
case time.Duration:
|
||||
return x, nil
|
||||
case float64:
|
||||
return time.Duration(x), nil
|
||||
case string:
|
||||
return time.ParseDuration(x)
|
||||
default:
|
||||
return 0, fmt.Errorf("invalid format")
|
||||
}
|
||||
d, err := time.ParseDuration(s)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
parseHeaderMap := func(v interface{}) (map[string][]string, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user