Files
play-with-docker/handlers/session_setup.go
Jonathan Leibiusky @xetorthio 954c52471b Refactor storage to support shallow types.
Add Client to storage.
Fix client resizing issues.
2017-09-01 20:12:19 -03:00

36 lines
746 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{}
json.NewDecoder(req.Body).Decode(&body)
s := core.SessionGet(sessionId)
s.Host = req.Host
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
}
}