/
utils.go
45 lines (38 loc) · 1.15 KB
/
utils.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package teststruct
import (
"fmt"
"time"
)
// unmarshallConfigTestStruct convert raw json data into more easily manipulated types
func unmarshallConfigTestStruct(ctjson configTestStructJson) (configTestStruct, error) {
// Convert string duration format (1d, 127ms...) to time.duration
cts := configTestStruct{
Concurrency: ctjson.Concurrency,
Retry: ctjson.Retry,
Frequency: map[string]time.Duration{},
Retrydelay: map[string]time.Duration{},
Timeout: map[string]time.Duration{},
}
for k, v := range ctjson.Frequency {
dur, err := time.ParseDuration(v)
if err != nil {
return cts, fmt.Errorf("%s: valid time units are [ns, us (or µs), ms, s, m, h", err)
}
cts.Frequency[k] = dur
}
for k, v := range ctjson.Timeout {
dur, err := time.ParseDuration(v)
if err != nil {
return cts, fmt.Errorf("%s: valid time units are [ns, us (or µs), ms, s, m, h", err)
}
cts.Timeout[k] = dur
}
for k, v := range ctjson.Retrydelay {
dur, err := time.ParseDuration(v)
if err != nil {
return cts, fmt.Errorf("%s: valid time units are [ns, us (or µs), ms, s, m, h", err)
}
cts.Retrydelay[k] = dur
}
return cts, nil
}