From c423a790d629b13c2eb1bc553beb3f61e30b3888 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 9 May 2013 23:52:12 +0200 Subject: [PATCH] fixed issue with viz --- api.go | 50 +++++++++++++++++++++++------------------------- api_test.go | 2 +- docker/docker.go | 2 +- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/api.go b/api.go index 6929bbd6e0..c62fd82f57 100644 --- a/api.go +++ b/api.go @@ -110,34 +110,30 @@ func getContainersExport(srv *Server, w http.ResponseWriter, r *http.Request) ([ } func getImages(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) { - vars := mux.Vars(r) - format := vars["format"] - if err := parseForm(r); err != nil { return nil, err } - if format == "viz" { - if err := srv.ImagesViz(w); err != nil { - return nil, err - } - return nil, nil - } else if format == "" || format == "json" { - all := r.Form.Get("all") == "1" - filter := r.Form.Get("filter") - only_ids := r.Form.Get("only_ids") == "1" + all := r.Form.Get("all") == "1" + filter := r.Form.Get("filter") + only_ids := r.Form.Get("only_ids") == "1" - outs, err := srv.Images(all, only_ids, filter) - if err != nil { - return nil, err - } - b, err := json.Marshal(outs) - if err != nil { - return nil, err - } - return b, nil + outs, err := srv.Images(all, only_ids, filter) + if err != nil { + return nil, err } - return nil, fmt.Errorf("No such format: %s", format) + b, err := json.Marshal(outs) + if err != nil { + return nil, err + } + return b, nil +} + +func getImagesViz(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) { + if err := srv.ImagesViz(w); err != nil { + return nil, err + } + return nil, nil } func getInfo(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) { @@ -508,7 +504,7 @@ func getImagesByName(srv *Server, w http.ResponseWriter, r *http.Request) ([]byt return b, nil } -func ListenAndServe(addr string, srv *Server) error { +func ListenAndServe(addr string, srv *Server, logging bool) error { r := mux.NewRouter() log.Printf("Listening for HTTP on %s\n", addr) @@ -518,7 +514,8 @@ func ListenAndServe(addr string, srv *Server) error { "/version": getVersion, "/containers/{name:.*}/export": getContainersExport, "/images": getImages, - "/images/{format}": getImages, + "/images/json": getImages, + "/images/viz": getImagesViz, "/info": getInfo, "/images/search": getImagesSearch, "/images/{name:.*}/history": getImagesHistory, @@ -558,8 +555,9 @@ func ListenAndServe(addr string, srv *Server) error { localFct := fct r.Path(localRoute).Methods(localMethod).HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Debugf("Calling %s %s", localMethod, localRoute) - log.Println(r.Method, r.RequestURI) - + if logging { + log.Println(r.Method, r.RequestURI) + } if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") { userAgent := strings.Split(r.Header.Get("User-Agent"), "/") if len(userAgent) == 2 && userAgent[1] != VERSION { diff --git a/api_test.go b/api_test.go index d92eacf519..d8c15a3014 100644 --- a/api_test.go +++ b/api_test.go @@ -17,7 +17,7 @@ func init() { srv := &Server{ runtime: runtime, } - go ListenAndServe("0.0.0.0:4243", srv) + go ListenAndServe("0.0.0.0:4243", srv, false) } diff --git a/docker/docker.go b/docker/docker.go index 7cfc39c03e..778326a810 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -102,5 +102,5 @@ func daemon(pidfile string, autoRestart bool) error { return err } - return docker.ListenAndServe("0.0.0.0:4243", server) + return docker.ListenAndServe("0.0.0.0:4243", server, true) }