예제 #1
0
func UpdateTopo(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)
	tid, _ := strconv.ParseInt(vars["Topoid"], 10, 64)

	var topo dbconn.Topo

	if err := topo.Parse(w, r); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if tid != topo.Id {
		err := fmt.Errorf("Topoid mismatch")
		http.Error(w, err.Error(), 500)
		return
	}

	if err := topo.Update(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	if err := json.NewEncoder(w).Encode(topo); err != nil {
		panic(err)
	}

}
예제 #2
0
func AddTopo(w http.ResponseWriter, r *http.Request) {

	var topo dbconn.Topo
	var cpe dbconn.Cpe

	if err := topo.Parse(w, r); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if err := topo.Add(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	cpe.Id = topo.Cpeid
	if err := cpe.Get(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	cpe.Topoid = topo.Id
	if err := cpe.Update(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	if err := json.NewEncoder(w).Encode(topo); err != nil {
		panic(err)
	}

}