From cfeab585c0e831ef073c689c065a52b84ae08761 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 22 Jul 2015 03:32:59 +0000 Subject: [PATCH] fix golint errors/warnings of pkg `api/` Signed-off-by: Zhang Wei --- api/common.go | 27 ++++++++++++++++----------- hack/make/validate-lint | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/api/common.go b/api/common.go index d31c557e9a..3442173d12 100644 --- a/api/common.go +++ b/api/common.go @@ -16,22 +16,26 @@ import ( // Common constants for daemon and client. const ( - // Current REST API version + // Version of Current REST API Version version.Version = "1.21" - // Minimun REST API version supported + // MinVersion represents Minimun REST API version supported MinVersion version.Version = "1.12" - // Default filename with Docker commands, read by docker build + // DefaultDockerfileName is the Default filename with Docker commands, read by docker build DefaultDockerfileName string = "Dockerfile" ) -type ByPrivatePort []types.Port +// byPrivatePort is temporary type used to sort types.Port by PrivatePort +type byPrivatePort []types.Port -func (r ByPrivatePort) Len() int { return len(r) } -func (r ByPrivatePort) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r ByPrivatePort) Less(i, j int) bool { return r[i].PrivatePort < r[j].PrivatePort } +func (r byPrivatePort) Len() int { return len(r) } +func (r byPrivatePort) Swap(i, j int) { r[i], r[j] = r[j], r[i] } +func (r byPrivatePort) Less(i, j int) bool { return r[i].PrivatePort < r[j].PrivatePort } +// DisplayablePorts returns formatted string representing open ports of container +// e.g. "0.0.0.0:80->9090/tcp, 9988/tcp" +// it's used by command 'docker ps' func DisplayablePorts(ports []types.Port) string { var ( result = []string{} @@ -41,7 +45,7 @@ func DisplayablePorts(ports []types.Port) string { ) firstInGroupMap = make(map[string]int) lastInGroupMap = make(map[string]int) - sort.Sort(ByPrivatePort(ports)) + sort.Sort(byPrivatePort(ports)) for _, port := range ports { var ( current = port.PrivatePort @@ -69,18 +73,18 @@ func DisplayablePorts(ports []types.Port) string { lastInGroupMap[portKey] = current continue } - result = append(result, FormGroup(portKey, firstInGroup, lastInGroup)) + result = append(result, formGroup(portKey, firstInGroup, lastInGroup)) firstInGroupMap[portKey] = current lastInGroupMap[portKey] = current } for portKey, firstInGroup := range firstInGroupMap { - result = append(result, FormGroup(portKey, firstInGroup, lastInGroupMap[portKey])) + result = append(result, formGroup(portKey, firstInGroup, lastInGroupMap[portKey])) } result = append(result, hostMappings...) return strings.Join(result, ", ") } -func FormGroup(key string, start, last int) string { +func formGroup(key string, start, last int) string { var ( group string parts = strings.Split(key, "/") @@ -102,6 +106,7 @@ func FormGroup(key string, start, last int) string { return fmt.Sprintf("%s/%s", group, groupType) } +// MatchesContentType validates the content type against the expected one func MatchesContentType(contentType, expectedType string) bool { mimetype, _, err := mime.ParseMediaType(contentType) if err != nil { diff --git a/hack/make/validate-lint b/hack/make/validate-lint index 874919f500..c559fbb5bf 100644 --- a/hack/make/validate-lint +++ b/hack/make/validate-lint @@ -8,6 +8,7 @@ source "${MAKEDIR}/.validate" # packages=( $(go list ./... 2> /dev/null | grep -vE "^github.com/docker/docker/vendor" || true ) ) packages=( + api api/server api/client api/client/ps