示例#1
0
文件: http.go 项目: nyaruka/gojunebug
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)
}
示例#2
0
文件: http.go 项目: nyaruka/gojunebug
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)
}