forked from play-with-docker/play-with-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_setup.go
38 lines (31 loc) · 833 Bytes
/
session_setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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, err := core.SessionGet(sessionId)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
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
}
}