/
docker_config.go
60 lines (52 loc) · 1.27 KB
/
docker_config.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
package config
import (
"fmt"
"os"
"github.com/fatih/structs"
)
func (d *DockerConfig) FullArgs() []string {
args := []string{}
args = append(args, generateEngineOptsSlice(d.EngineOpts)...)
args = append(args, d.ExtraArgs...)
if d.TLS {
args = append(args, d.TLSArgs...)
}
return args
}
func (d *DockerConfig) AppendEnv() []string {
return append(os.Environ(), d.Environment...)
}
func generateEngineOptsSlice(opts EngineOpts) []string {
optsStruct := structs.New(opts)
var optsSlice []string
for k, v := range optsStruct.Map() {
optTag := optsStruct.Field(k).Tag("opt")
switch value := v.(type) {
case string:
if value != "" {
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag), value)
}
case *bool:
if value != nil {
if *value {
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag))
} else {
optsSlice = append(optsSlice, fmt.Sprintf("--%s=false", optTag))
}
}
case []string:
for _, elem := range value {
if elem != "" {
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag), elem)
}
}
case map[string]string:
for k, v := range value {
if v != "" {
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag), fmt.Sprintf("%s=%s", k, v))
}
}
}
}
return optsSlice
}