Refactor api.go to use a factory with named functions

This commit is contained in:
Guillaume J. Charmes 2013-05-07 16:33:12 -07:00
parent a0880edc63
commit b56b2da5c5
3 changed files with 733 additions and 620 deletions

1340
api.go

File diff suppressed because it is too large Load Diff

View File

@ -35,8 +35,10 @@ func checkRemoteVersion() error {
}
var out ApiVersion
err = json.Unmarshal(body, &out)
if err != nil {
Debugf("Error unmarshal: body: %s, err: %s\n", body, err)
return err
}
if out.Version != VERSION {
@ -323,6 +325,7 @@ func CmdVersion(args ...string) error {
var out ApiVersion
err = json.Unmarshal(body, &out)
if err != nil {
Debugf("Error unmarshal: body: %s, err: %s\n", body, err)
return err
}
fmt.Println("Version:", out.Version)
@ -1213,7 +1216,7 @@ func hijack(method, path string, setRawTerminal bool) error {
sendStdin := Go(func() error {
_, err := io.Copy(rwc, os.Stdin)
if err := rwc.(*net.TCPConn).CloseWrite(); err != nil {
fmt.Fprintf(os.Stderr, "Couldn't send EOF: "+err.Error())
fmt.Fprintf(os.Stderr, "Couldn't send EOF: %s\n", err)
}
return err
})

View File

@ -316,7 +316,7 @@ func (srv *Server) ImagePush(name, registry string, file *os.File) error {
img, err := srv.runtime.graph.Get(name)
if err != nil {
Debugf("The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name]))
// If it fails, try to get the repository
// If it fails, try to get the repository
if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
if err := srv.runtime.graph.PushRepository(file, name, localRepo, srv.runtime.authConfig); err != nil {
return err
@ -350,8 +350,8 @@ func (srv *Server) ImageImport(src, repo, tag string, file *os.File) error {
u.Path = ""
}
fmt.Fprintln(file, "Downloading from", u)
// Download with curl (pretty progress bar)
// If curl is not available, fallback to http.Get()
// Download with curl (pretty progress bar)
// If curl is not available, fallback to http.Get()
resp, err = Download(u.String(), file)
if err != nil {
return err
@ -362,7 +362,7 @@ func (srv *Server) ImageImport(src, repo, tag string, file *os.File) error {
if err != nil {
return err
}
// Optionally register the image at REPO/TAG
// Optionally register the image at REPO/TAG
if repo != "" {
if err := srv.runtime.repositories.Set(repo, tag, img.Id, true); err != nil {
return err