From 551355c9adac6a8b36244e1962e7a104611ae4af Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 24 Feb 2014 11:48:14 -0800 Subject: [PATCH 1/2] api/common.go: code shared by the server and client implementation of the Docker remote api. Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- api/common.go | 45 +++++++++++++++++++++++++++++++++++++++ api/{api.go => server.go} | 37 -------------------------------- 2 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 api/common.go rename api/{api.go => server.go} (96%) diff --git a/api/common.go b/api/common.go new file mode 100644 index 0000000000..59e7d3d525 --- /dev/null +++ b/api/common.go @@ -0,0 +1,45 @@ +package api + +import ( + "fmt" + "github.com/dotcloud/docker/engine" + "github.com/dotcloud/docker/utils" + "mime" + "strings" +) + +const ( + APIVERSION = 1.9 + DEFAULTHTTPHOST = "127.0.0.1" + DEFAULTUNIXSOCKET = "/var/run/docker.sock" +) + +func ValidateHost(val string) (string, error) { + host, err := utils.ParseHost(DEFAULTHTTPHOST, DEFAULTUNIXSOCKET, val) + if err != nil { + return val, err + } + return host, nil +} + +//TODO remove, used on < 1.5 in getContainersJSON +func displayablePorts(ports *engine.Table) string { + result := []string{} + for _, port := range ports.Data { + if port.Get("IP") == "" { + result = append(result, fmt.Sprintf("%d/%s", port.GetInt("PublicPort"), port.Get("Type"))) + } else { + result = append(result, fmt.Sprintf("%s:%d->%d/%s", port.Get("IP"), port.GetInt("PublicPort"), port.GetInt("PrivatePort"), port.Get("Type"))) + } + } + return strings.Join(result, ", ") +} + +func MatchesContentType(contentType, expectedType string) bool { + mimetype, _, err := mime.ParseMediaType(contentType) + if err != nil { + utils.Errorf("Error parsing media type: %s error: %s", contentType, err.Error()) + } + return err == nil && mimetype == expectedType +} + diff --git a/api/api.go b/api/server.go similarity index 96% rename from api/api.go rename to api/server.go index 0fe1eb0fee..4b10a2dae1 100644 --- a/api/api.go +++ b/api/server.go @@ -17,7 +17,6 @@ import ( "io" "io/ioutil" "log" - "mime" "net" "net/http" "net/http/pprof" @@ -29,25 +28,10 @@ import ( "time" ) -// FIXME: move code common to client and server to common.go -const ( - APIVERSION = 1.9 - DEFAULTHTTPHOST = "127.0.0.1" - DEFAULTUNIXSOCKET = "/var/run/docker.sock" -) - var ( activationLock chan struct{} ) -func ValidateHost(val string) (string, error) { - host, err := utils.ParseHost(DEFAULTHTTPHOST, DEFAULTUNIXSOCKET, val) - if err != nil { - return val, err - } - return host, nil -} - type HttpApiFunc func(eng *engine.Engine, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) { @@ -129,27 +113,6 @@ func getBoolParam(value string) (bool, error) { return ret, nil } -//TODO remove, used on < 1.5 in getContainersJSON -func displayablePorts(ports *engine.Table) string { - result := []string{} - for _, port := range ports.Data { - if port.Get("IP") == "" { - result = append(result, fmt.Sprintf("%d/%s", port.GetInt("PublicPort"), port.Get("Type"))) - } else { - result = append(result, fmt.Sprintf("%s:%d->%d/%s", port.Get("IP"), port.GetInt("PublicPort"), port.GetInt("PrivatePort"), port.Get("Type"))) - } - } - return strings.Join(result, ", ") -} - -func MatchesContentType(contentType, expectedType string) bool { - mimetype, _, err := mime.ParseMediaType(contentType) - if err != nil { - utils.Errorf("Error parsing media type: %s error: %s", contentType, err.Error()) - } - return err == nil && mimetype == expectedType -} - func postAuth(eng *engine.Engine, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { var ( authConfig, err = ioutil.ReadAll(r.Body) From 4434b63ff44c6994366afebeceb9b570bb9ee26c Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 24 Feb 2014 23:10:45 +0000 Subject: [PATCH 2/2] fix gofmt Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- api/common.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/common.go b/api/common.go index 59e7d3d525..c79b16fda2 100644 --- a/api/common.go +++ b/api/common.go @@ -42,4 +42,3 @@ func MatchesContentType(contentType, expectedType string) bool { } return err == nil && mimetype == expectedType } -