-
Notifications
You must be signed in to change notification settings - Fork 51
/
timeouts.go
61 lines (53 loc) · 1.46 KB
/
timeouts.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"strconv"
"time"
"github.com/reconquest/hierr-go"
"github.com/reconquest/runcmd"
)
func makeTimeouts(args map[string]interface{}) (*runcmd.Timeout, error) {
var (
connectionTimeoutRaw = args["--conn-timeout"].(string)
sendTimeoutRaw = args["--send-timeout"].(string)
receiveTimeoutRaw = args["--recv-timeout"].(string)
keepAliveRaw = args["--keep-alive"].(string)
)
connectionTimeout, err := strconv.Atoi(connectionTimeoutRaw)
if err != nil {
return nil, hierr.Errorf(
err,
`can't convert specified connection timeout to number: '%s'`,
connectionTimeoutRaw,
)
}
sendTimeout, err := strconv.Atoi(sendTimeoutRaw)
if err != nil {
return nil, hierr.Errorf(
err,
`can't convert specified send timeout to number: '%s'`,
sendTimeoutRaw,
)
}
receiveTimeout, err := strconv.Atoi(receiveTimeoutRaw)
if err != nil {
return nil, hierr.Errorf(
err,
`can't convert specified receive timeout to number: '%s'`,
receiveTimeoutRaw,
)
}
keepAlive, err := strconv.Atoi(keepAliveRaw)
if err != nil {
return nil, hierr.Errorf(
err,
`can't convert specified keep alive time to number: '%s'`,
keepAliveRaw,
)
}
return &runcmd.Timeout{
Connection: time.Millisecond * time.Duration(connectionTimeout),
Send: time.Millisecond * time.Duration(sendTimeout),
Receive: time.Millisecond * time.Duration(receiveTimeout),
KeepAlive: time.Millisecond * time.Duration(keepAlive),
}, nil
}