Пример #1
0
func DeleteTopo(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)
	var topo dbconn.Topo
	var cpe dbconn.Cpe
	var err error

	topo.Id, err = strconv.ParseInt(vars["Topoid"], 10, 64)

	// Need to clear the TopoID on the associated CPE - set it to Topoid = 0
	if err = topo.Get(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	cpe.Id = topo.Cpeid
	cpe.Topoid = 0
	if err = cpe.Update(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	//Delete the topo from Topos Table
	if err = topo.Delete(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

}
Пример #2
0
func GetCpeTopo(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)

	var cpe dbconn.Cpe
	var topo dbconn.Topo
	var err error

	cpe.Id, err = strconv.ParseInt(vars["Cpeid"], 10, 64)

	if err = cpe.Get(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	topo.Id = cpe.Topoid
	if err = topo.Get(); 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)
	}

}