This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_timeout.go
81 lines (73 loc) · 3.01 KB
/
config_timeout.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package docker
import (
"bytes"
"encoding/json"
"time"
)
// TimeoutConfig drives the various timeouts in the Docker backend.
type TimeoutConfig struct {
// ContainerStart is the maximum time starting a container may take.
ContainerStart time.Duration `json:"containerStart" yaml:"containerStart" default:"60s"`
// ContainerStop is the maximum time to wait for a container to stop. This should always be set higher than the Docker StopTimeout.
ContainerStop time.Duration `json:"containerStop" yaml:"containerStop" default:"60s"`
// CommandStart sets the maximum time starting a command may take.
CommandStart time.Duration `json:"commandStart" yaml:"commandStart" default:"60s"`
// Signal sets the maximum time sending a signal may take.
Signal time.Duration `json:"signal" yaml:"signal" default:"60s"`
// Signal sets the maximum time setting the window size may take.
Window time.Duration `json:"window" yaml:"window" default:"60s"`
// HTTP
HTTP time.Duration `json:"http" yaml:"http" default:"15s"`
}
type tmpTimeoutConfig struct {
// ContainerStart is the maximum time starting a container may take.
ContainerStart interface{} `json:"containerStart" yaml:"containerStart" default:"60s"`
// ContainerStop is the maximum time to wait for a container to stop. This should always be set higher than the Docker StopTimeout.
ContainerStop interface{} `json:"containerStop" yaml:"containerStop" default:"60s"`
// CommandStart sets the maximum time starting a command may take.
CommandStart interface{} `json:"commandStart" yaml:"commandStart" default:"60s"`
// Signal sets the maximum time sending a signal may take.
Signal interface{} `json:"signal" yaml:"signal" default:"60s"`
// Signal sets the maximum time setting the window size may take.
Window interface{} `json:"window" yaml:"window" default:"60s"`
// HTTP
HTTP interface{} `json:"http" yaml:"http" default:"15s"`
}
// UnmarshalJSON takes a JSON byte array and unmarshalls it into a structure.
func (t *TimeoutConfig) UnmarshalJSON(b []byte) error {
decoder := json.NewDecoder(bytes.NewReader(b))
tmp := &tmpTimeoutConfig{}
if err := decoder.Decode(tmp); err != nil {
return err
}
return t.unmarshalTmp(tmp)
}
// UnmarshalYAML takes a YAML byte array and unmarshalls it into a structure.
func (t *TimeoutConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
tmp := &tmpTimeoutConfig{}
if err := unmarshal(tmp); err != nil {
return err
}
return t.unmarshalTmp(tmp)
}
func (t *TimeoutConfig) unmarshalTmp(tmp *tmpTimeoutConfig) error {
if err := parseRawDuration(tmp.ContainerStart, &t.ContainerStart); err != nil {
return err
}
if err := parseRawDuration(tmp.ContainerStop, &t.ContainerStop); err != nil {
return err
}
if err := parseRawDuration(tmp.CommandStart, &t.CommandStart); err != nil {
return err
}
if err := parseRawDuration(tmp.Signal, &t.Signal); err != nil {
return err
}
if err := parseRawDuration(tmp.Window, &t.Window); err != nil {
return err
}
if err := parseRawDuration(tmp.HTTP, &t.HTTP); err != nil {
return err
}
return nil
}