github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/pkg/api/handlers/compat/containers_start.go (about) 1 package compat 2 3 import ( 4 "net/http" 5 6 "github.com/containers/libpod/libpod" 7 "github.com/containers/libpod/libpod/define" 8 "github.com/containers/libpod/pkg/api/handlers/utils" 9 "github.com/gorilla/schema" 10 "github.com/pkg/errors" 11 ) 12 13 func StartContainer(w http.ResponseWriter, r *http.Request) { 14 decoder := r.Context().Value("decoder").(*schema.Decoder) 15 query := struct { 16 DetachKeys string `schema:"detachKeys"` 17 }{ 18 // Override golang default values for types 19 } 20 if err := decoder.Decode(&query, r.URL.Query()); err != nil { 21 utils.BadRequest(w, "url", r.URL.String(), err) 22 return 23 } 24 if len(query.DetachKeys) > 0 { 25 // TODO - start does not support adding detach keys 26 utils.BadRequest(w, "detachKeys", query.DetachKeys, errors.New("the detachKeys parameter is not supported yet")) 27 return 28 } 29 runtime := r.Context().Value("runtime").(*libpod.Runtime) 30 name := utils.GetName(r) 31 con, err := runtime.LookupContainer(name) 32 if err != nil { 33 utils.ContainerNotFound(w, name, err) 34 return 35 } 36 37 state, err := con.State() 38 if err != nil { 39 utils.InternalServerError(w, err) 40 return 41 } 42 if state == define.ContainerStateRunning { 43 utils.WriteResponse(w, http.StatusNotModified, "") 44 return 45 } 46 if err := con.Start(r.Context(), false); err != nil { 47 utils.InternalServerError(w, err) 48 return 49 } 50 utils.WriteResponse(w, http.StatusNoContent, "") 51 }