-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutils.go
46 lines (40 loc) · 1.08 KB
/
utils.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
package main
import (
"os"
"strings"
)
//credentials format: <username>:<password>
func parseCredentials(credentials string) (string, string) {
comps := strings.SplitN(credentials, ":", 2)
if len(comps) != 2 {
return "", ""
}
return comps[0], comps[1]
}
//image format: <repository>/<image_name>:<tag>. tag defaults to latest, repository defaults to library
func parseImageNameTag(imageNameTag string) (imageName, imageTag string) {
if strings.Contains(imageNameTag, ":") {
imageName = strings.SplitN(imageNameTag, ":", 2)[0]
imageTag = strings.SplitN(imageNameTag, ":", 2)[1]
} else {
imageName = imageNameTag
imageTag = "latest"
}
if !strings.Contains(imageName, "/") {
imageName = "library/" + imageName
}
return
}
//return whether imageName is an official image or not
func isOfficialImage(imageName string) bool {
return strings.HasPrefix(imageName, "library/")
}
//fileExists reports whether the named file or directory exists
func fileExists(path string) bool {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}