Last active
December 18, 2015 10:49
-
-
Save crosbymichael/5770907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | |
if err := parseForm(r); err != nil { | |
return err | |
} | |
src := r.Form.Get("fromSrc") | |
image := r.Form.Get("fromImage") | |
tag := r.Form.Get("tag") | |
repo := r.Form.Get("repo") | |
sf := utils.NewStreamFormatter(version > 1.0) | |
if version > 1.0 { | |
w.Header().Set("Content-Type", "application/json") | |
} | |
//We try to upgrade the connection to a web socket if requested, else we use the existing | |
//implementation | |
if version > 1.1 { | |
ws, err := newWebsocketWriter(w, r) | |
if err != nil { | |
if !isHandshakeError(err) { | |
w.Write(sf.FormatError(err)) | |
return err | |
} | |
} else { | |
defer ws.Close() | |
w = ws | |
} | |
} | |
if image != "" { //pull | |
registry := r.Form.Get("registry") | |
if err := srv.ImagePull(image, tag, registry, w, sf); err != nil { | |
if sf.Used() { | |
w.Write(sf.FormatError(err)) | |
return nil | |
} | |
return err | |
} | |
} else { //import | |
if err := srv.ImageImport(src, repo, tag, r.Body, w, sf); err != nil { | |
if sf.Used() { | |
w.Write(sf.FormatError(err)) | |
return nil | |
} | |
return err | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment