Add session templates

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-06-06 14:48:26 -03:00
parent fe8ea11fc6
commit 6d992b5d02
11 changed files with 535 additions and 3 deletions

35
handlers/session_setup.go Normal file
View File

@@ -0,0 +1,35 @@
package handlers
import (
"encoding/json"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/play-with-docker/play-with-docker/pwd"
)
func SessionSetup(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
sessionId := vars["sessionId"]
body := pwd.SessionSetupConf{}
json.NewDecoder(req.Body).Decode(&body)
s := core.SessionGet(sessionId)
if len(s.Instances) > 0 {
log.Println("Cannot setup a session that contains instances")
rw.WriteHeader(http.StatusConflict)
rw.Write([]byte("Cannot setup a session that contains instances"))
return
}
err := core.SessionSetup(s, body)
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
}