bump api version and ensure backward compat

This commit is contained in:
Nate Jones 2013-10-06 05:59:49 +00:00
parent 15867ff430
commit d7928b9a67
2 changed files with 42 additions and 2 deletions

13
api.go
View file

@ -23,7 +23,7 @@ import (
)
const (
APIVERSION = 1.6
APIVERSION = 1.7
DEFAULTHTTPHOST = "127.0.0.1"
DEFAULTHTTPPORT = 4243
DEFAULTUNIXSOCKET = "/var/run/docker.sock"
@ -191,7 +191,16 @@ func getImagesJSON(srv *Server, version float64, w http.ResponseWriter, r *http.
return err
}
return writeJSON(w, http.StatusOK, outs)
if version < 1.7 {
outs2 := []APIImagesOld{}
for _, ctnr := range outs {
outs2 = append(outs2, ctnr.ToLegacy()...)
}
return writeJSON(w, http.StatusOK, outs2)
} else {
return writeJSON(w, http.StatusOK, outs)
}
}
func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {

View file

@ -1,5 +1,7 @@
package docker
import "strings"
type APIHistory struct {
ID string `json:"Id"`
Tags []string `json:",omitempty"`
@ -17,6 +19,35 @@ type APIImages struct {
ParentId string `json:",omitempty"`
}
type APIImagesOld struct {
Repository string `json:",omitempty"`
Tag string `json:",omitempty"`
ID string `json:"Id"`
Created int64
Size int64
VirtualSize int64
}
func (self *APIImages) ToLegacy() []APIImagesOld {
outs := []APIImagesOld{}
for _, repotag := range self.RepoTags {
components := strings.SplitN(repotag, ":", 2)
outs = append(outs, APIImagesOld{
ID: self.ID,
Repository: components[0],
Tag: components[1],
Created: self.Created,
Size: self.Size,
VirtualSize: self.VirtualSize,
})
}
return outs
}
type APIInfo struct {
Debug bool
Containers int