浏览代码

Bumped API version in api.go ; added <1.5 behavior to getContainersJSON

shin- 12 年之前
父节点
当前提交
9ae5054c34
共有 2 个文件被更改,包括 36 次插入2 次删除
  1. 12 2
      api.go
  2. 24 0
      api_params.go

+ 12 - 2
api.go

@@ -21,7 +21,7 @@ import (
 	"strings"
 )
 
-const APIVERSION = 1.4
+const APIVERSION = 1.5
 const DEFAULTHTTPHOST = "127.0.0.1"
 const DEFAULTHTTPPORT = 4243
 const DEFAULTUNIXSOCKET = "/var/run/docker.sock"
@@ -327,8 +327,18 @@ func getContainersJSON(srv *Server, version float64, w http.ResponseWriter, r *h
 		n = -1
 	}
 
+	var b []byte
 	outs := srv.Containers(all, size, n, since, before)
-	b, err := json.Marshal(outs)
+	if version < 1.5 {
+		outs2 := []APIContainersOld{}
+		for _, ctnr := range outs {
+			outs2 = append(outs2, ctnr.ToLegacy())
+		}
+		b, err = json.Marshal(outs2)
+	} else {
+		b, err = json.Marshal(outs)
+	}
+
 	if err != nil {
 		return err
 	}

+ 24 - 0
api_params.go

@@ -54,6 +54,30 @@ type APIContainers struct {
 	SizeRootFs int64
 }
 
+func (self *APIContainers) ToLegacy() APIContainersOld {
+	return APIContainersOld{
+		ID: self.ID,
+		Image: self.Image,
+		Command: self.Command,
+		Created: self.Created,
+		Status: self.Status,
+		Ports: displayablePorts(self.Ports),
+		SizeRw: self.SizeRw,
+		SizeRootFs: self.SizeRootFs,
+	}
+}
+
+type APIContainersOld struct {
+	ID         string `json:"Id"`
+	Image      string
+	Command    string
+	Created    int64
+	Status     string
+	Ports      string
+	SizeRw     int64
+	SizeRootFs int64
+}
+
 type APISearch struct {
 	Name        string
 	Description string