Skip to content

Commit

Permalink
Add close session endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosnils committed Sep 26, 2017
1 parent 98735a5 commit 1a7a776
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions handlers/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 26 additions & 0 deletions handlers/close_session.go
Original file line number Diff line number Diff line change
@@ -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
}

}

0 comments on commit 1a7a776

Please sign in to comment.