-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
opts_unix.go
37 lines (31 loc) · 993 Bytes
/
opts_unix.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
// +build !windows
package opts
import (
"fmt"
"strings"
)
// DefaultHTTPHost Default HTTP Host used if only port is provided to -H flag e.g. dockerd -H tcp://:8080
const DefaultHTTPHost = "localhost"
// MountParser parses mount path.
func MountParser(mount string) (source, destination string, err error) {
sd := strings.Split(mount, ":")
if len(sd) == 2 {
return sd[0], sd[1], nil
}
return "", "", fmt.Errorf("invalid mount format: got %s, expected <src>:<dst>", mount)
}
// VolumeParser parsed volume path.
func VolumeParser(volume string) (source, target string, readOnly bool, err error) {
st := strings.Split(volume, ":")
if len(st) == 3 {
if st[2] == "ro" {
return st[0], st[1], true, nil
} else {
return "", "", false, fmt.Errorf("invalid volume format: got %s, expected <src>:<trgt>:ro", volume)
}
}
if len(st) == 2 {
return st[0], st[1], false, nil
}
return "", "", false, fmt.Errorf("invalid volume format: got %s, expected <src>:<trgt>", volume)
}