Exemple #1
0
func readConnection(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	uuid := ps.ByName("conn_uuid")

	var resp ConnectionResponse

	// load our connection config
	connection, err := store.ConnectionFromUuid(uuid)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	resp.Connection = connection

	// load our status
	status, err := connection.GetStatus()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	resp.Status = status

	// output it
	js, err := json.Marshal(resp)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(js)
}
Exemple #2
0
func deleteConnection(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	uuid := ps.ByName("conn_uuid")
	var resp ConnectionResponse

	// load our connection config
	connection, err := store.ConnectionFromUuid(uuid)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	resp.Connection = connection

	// load our status
	status, err := connection.GetStatus()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	resp.Status = status

	// output it
	js, err := json.Marshal(resp)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// shut down our connection
	engine, exists := engines[uuid]
	if exists {
		engine.Stop()
		delete(engines, uuid)
	}

	// remove all our data for it
	connection.Delete()

	w.Header().Set("Content-Type", "application/json")
	w.Write(js)
}