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

This commit is contained in:
shin- 2013-09-04 23:41:44 +02:00
parent 98edd0e751
commit 9ae5054c34
2 changed files with 36 additions and 2 deletions

14
api.go
View File

@ -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
}

View File

@ -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