forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
69 lines (59 loc) · 1.37 KB
/
options.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
package containerio
import (
"net/http"
)
// Option is used to pass some data into ContainerIO.
type Option struct {
id string
rootDir string
backends map[string]struct{}
hijack http.Hijacker
hijackUpgrade bool
stdinBackend string
}
// NewOption creates the Option instance.
func NewOption(opts ...func(*Option)) *Option {
opt := &Option{}
for _, o := range opts {
o(opt)
}
return opt
}
// WithID specified the container's id.
func WithID(id string) func(*Option) {
return func(opt *Option) {
opt.id = id
}
}
// WithRootDir specified the container's root dir.
func WithRootDir(dir string) func(*Option) {
return func(opt *Option) {
opt.rootDir = dir
}
}
// WithRawFile specified the raw-file backend.
func WithRawFile() func(*Option) {
return func(opt *Option) {
if opt.backends == nil {
opt.backends = make(map[string]struct{})
}
opt.backends["raw-file"] = struct{}{}
}
}
// WithHijack specified the hijack backend.
func WithHijack(hi http.Hijacker, upgrade bool) func(*Option) {
return func(opt *Option) {
if opt.backends == nil {
opt.backends = make(map[string]struct{})
}
opt.backends["hijack"] = struct{}{}
opt.hijack = hi
opt.hijackUpgrade = upgrade
}
}
// WithStdinHijack sepcified the stdin with hijack.
func WithStdinHijack() func(*Option) {
return func(opt *Option) {
opt.stdinBackend = "hijack"
}
}