Browse code

fix golint errors/warnings of pkg `api/`

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>

root authored on 2015/07/22 12:32:59
Showing 2 changed files
... ...
@@ -16,22 +16,26 @@ import (
16 16
 
17 17
 // Common constants for daemon and client.
18 18
 const (
19
-	// Current REST API version
19
+	// Version of Current REST API
20 20
 	Version version.Version = "1.21"
21 21
 
22
-	// Minimun REST API version supported
22
+	// MinVersion represents Minimun REST API version supported
23 23
 	MinVersion version.Version = "1.12"
24 24
 
25
-	// Default filename with Docker commands, read by docker build
25
+	// DefaultDockerfileName is the Default filename with Docker commands, read by docker build
26 26
 	DefaultDockerfileName string = "Dockerfile"
27 27
 )
28 28
 
29
-type ByPrivatePort []types.Port
29
+// byPrivatePort is temporary type used to sort types.Port by PrivatePort
30
+type byPrivatePort []types.Port
30 31
 
31
-func (r ByPrivatePort) Len() int           { return len(r) }
32
-func (r ByPrivatePort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
33
-func (r ByPrivatePort) Less(i, j int) bool { return r[i].PrivatePort < r[j].PrivatePort }
32
+func (r byPrivatePort) Len() int           { return len(r) }
33
+func (r byPrivatePort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
34
+func (r byPrivatePort) Less(i, j int) bool { return r[i].PrivatePort < r[j].PrivatePort }
34 35
 
36
+// DisplayablePorts returns formatted string representing open ports of container
37
+// e.g. "0.0.0.0:80->9090/tcp, 9988/tcp"
38
+// it's used by command 'docker ps'
35 39
 func DisplayablePorts(ports []types.Port) string {
36 40
 	var (
37 41
 		result          = []string{}
... ...
@@ -41,7 +45,7 @@ func DisplayablePorts(ports []types.Port) string {
41 41
 	)
42 42
 	firstInGroupMap = make(map[string]int)
43 43
 	lastInGroupMap = make(map[string]int)
44
-	sort.Sort(ByPrivatePort(ports))
44
+	sort.Sort(byPrivatePort(ports))
45 45
 	for _, port := range ports {
46 46
 		var (
47 47
 			current      = port.PrivatePort
... ...
@@ -69,18 +73,18 @@ func DisplayablePorts(ports []types.Port) string {
69 69
 			lastInGroupMap[portKey] = current
70 70
 			continue
71 71
 		}
72
-		result = append(result, FormGroup(portKey, firstInGroup, lastInGroup))
72
+		result = append(result, formGroup(portKey, firstInGroup, lastInGroup))
73 73
 		firstInGroupMap[portKey] = current
74 74
 		lastInGroupMap[portKey] = current
75 75
 	}
76 76
 	for portKey, firstInGroup := range firstInGroupMap {
77
-		result = append(result, FormGroup(portKey, firstInGroup, lastInGroupMap[portKey]))
77
+		result = append(result, formGroup(portKey, firstInGroup, lastInGroupMap[portKey]))
78 78
 	}
79 79
 	result = append(result, hostMappings...)
80 80
 	return strings.Join(result, ", ")
81 81
 }
82 82
 
83
-func FormGroup(key string, start, last int) string {
83
+func formGroup(key string, start, last int) string {
84 84
 	var (
85 85
 		group     string
86 86
 		parts     = strings.Split(key, "/")
... ...
@@ -102,6 +106,7 @@ func FormGroup(key string, start, last int) string {
102 102
 	return fmt.Sprintf("%s/%s", group, groupType)
103 103
 }
104 104
 
105
+// MatchesContentType validates the content type against the expected one
105 106
 func MatchesContentType(contentType, expectedType string) bool {
106 107
 	mimetype, _, err := mime.ParseMediaType(contentType)
107 108
 	if err != nil {
... ...
@@ -8,6 +8,7 @@ source "${MAKEDIR}/.validate"
8 8
 # packages=( $(go list ./... 2> /dev/null | grep -vE "^github.com/docker/docker/vendor" || true ) )
9 9
 
10 10
 packages=(
11
+	api
11 12
 	api/server
12 13
 	api/client
13 14
 	api/client/ps