1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-14 01:57:32 +08:00
docker-labs/handlers/new_instance.go
Jonathan Leibiusky (@xetorthio) 8e4981d24f Huge refactor to have everything working with socket.io
It fixes lots of bugs, can fallback to long polling, resize viewport of
terminals and share clients state of the session, so they all see the
same thing.
2016-11-10 10:42:08 -03:00

34 lines
558 B
Go

package handlers
import (
"encoding/json"
"log"
"net/http"
"github.com/franela/play-with-docker/services"
"github.com/gorilla/mux"
)
func NewInstance(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
sessionId := vars["sessionId"]
s := services.GetSession(sessionId)
s.Lock()
if len(s.Instances) >= 5 {
s.Unlock()
rw.WriteHeader(http.StatusConflict)
return
}
i, err := services.NewInstance(s)
s.Unlock()
if err != nil {
log.Println(err)
//TODO: Set a status error
} else {
json.NewEncoder(rw).Encode(i)
}
}