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:
40
handlers/exec.go
Normal file
40
handlers/exec.go
Normal 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})
|
||||
}
|
||||
Reference in New Issue
Block a user