Files
play-with-docker/handlers/session_setup.go
2017-09-12 17:58:56 -03:00

35 lines
751 B
Go

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{PlaygroundFQDN: req.Host}
json.NewDecoder(req.Body).Decode(&body)
s := core.SessionGet(sessionId)
err := core.SessionSetup(s, body)
if err != nil {
if pwd.SessionNotEmpty(err) {
log.Println("Cannot setup a session that contains instances")
rw.WriteHeader(http.StatusConflict)
rw.Write([]byte("Cannot setup a session that contains instances"))
return
}
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
}