Exemple #1
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)
	}

}
Exemple #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)
	}

}