-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathutil.go
More file actions
30 lines (24 loc) · 645 Bytes
/
Copy pathutil.go
File metadata and controls
30 lines (24 loc) · 645 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package goconfig
import (
"fmt"
"reflect"
"strconv"
"time"
)
func set(dest, value interface{}) {
dest_v := reflect.ValueOf(dest)
dest_t := reflect.TypeOf(dest)
value_v := reflect.ValueOf(value)
dest_v.Elem().Set(value_v.Convert(dest_t).Elem())
}
func unmarshalDurationString(s string) (time.Duration, error) {
// nanoseconds stored as a string
if i, err := strconv.ParseInt(s, 10, 64); err == nil {
return time.Duration(i), nil
}
// duration string
if d, err := time.ParseDuration(s); err == nil {
return d, nil
}
return 0, fmt.Errorf("invalid time.Duration format, use a duration string (like '15s') or nanoseconds")
}