示例#1
0
// DispatchJSON receives an extension json request
func DispatchJSON(w http.ResponseWriter, r *http.Request) {
	con := data.MakeContext(r)

	// get namespace
	namespace := mux.Vars(r)["namespace"]
	if namespace == "" {
		startpage.Dispatch(w, r)
		return
	}

	shareURL := r.URL.Query().Get("url")

	if err := share.URL(shareURL, namespace, con); err != nil {
		con.Log.Errorf("Error while sharing an URL. URL: %v. Error: %v", shareURL, err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	w.Write(statusOk)
}
示例#2
0
// DispatchJSON is called when a json request with an url is posted
func DispatchJSON(w http.ResponseWriter, r *http.Request) {
	con := data.MakeContext(r)

	// get namespace
	namespace := mux.Vars(r)["namespace"]
	if namespace == "" {
		startpage.Dispatch(w, r)
		return
	}

	empty, err := data.NamespaceIsEmpty(con, namespace)

	if err == nil {

		if empty {
			w.Write(statusOk)
		} else {
			w.Write(statusInUse)
		}

	} else {
		w.Write(statusError)
	}
}