Add support for setting stacks when creating session (#138)

* Add support for setting stacks when creating session

* Add exec endpoint and move dns stuff to another package

* Rename command and status code
This commit is contained in:
Marcos Nils
2017-05-11 10:34:16 -03:00
committed by GitHub
parent 24f8c9fc62
commit 62c5d3761d
9 changed files with 187 additions and 86 deletions

40
handlers/exec.go Normal file
View File

@@ -0,0 +1,40 @@
package handlers
import (
"encoding/json"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/play-with-docker/play-with-docker/services"
)
type execRequest struct {
Cmd []string `json:"command"`
}
type execResponse struct {
ExitCode int `json:"status_code"`
}
func Exec(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
instanceName := vars["instanceName"]
var er execRequest
err := json.NewDecoder(req.Body).Decode(&er)
if err != nil {
rw.WriteHeader(http.StatusBadRequest)
return
}
code, err := services.Exec(instanceName, er.Cmd)
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
json.NewEncoder(rw).Encode(execResponse{code})
}