Add close session endpoint

This commit is contained in:
Marcos Lilljedahl
2017-09-26 09:38:08 -03:00
parent 98735a5a93
commit 1a7a776a27
2 changed files with 27 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ func Register(extend HandlerExtender) {
r.HandleFunc("/ping", Ping).Methods("GET")
corsRouter.HandleFunc("/instances/images", GetInstanceImages).Methods("GET")
corsRouter.HandleFunc("/sessions/{sessionId}", GetSession).Methods("GET")
corsRouter.HandleFunc("/sessions/{sessionId}", CloseSession).Methods("DELETE")
corsRouter.HandleFunc("/sessions/{sessionId}/setup", SessionSetup).Methods("POST")
corsRouter.HandleFunc("/sessions/{sessionId}/instances", NewInstance).Methods("POST")
corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}/uploads", FileUpload).Methods("POST")

26
handlers/close_session.go Normal file
View File

@@ -0,0 +1,26 @@
package handlers
import (
"log"
"net/http"
"github.com/gorilla/mux"
)
func CloseSession(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
sessionId := vars["sessionId"]
session := core.SessionGet(sessionId)
if session == nil {
rw.WriteHeader(http.StatusNotFound)
return
}
if err := core.SessionClose(session); err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
}