Esempio n. 1
0
func UpdateVnf(w http.ResponseWriter, r *http.Request) {

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

	var vnf dbconn.Vnf

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

	if vid != vnf.Id {
		err := fmt.Errorf("Error: Vnfid mismatch")
		http.Error(w, err.Error(), 500)
		return
	}

	if err := vnf.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(vnf); err != nil {
		panic(err)
	}

}
Esempio n. 2
0
func DeleteVnf(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)

	var vnf dbconn.Vnf
	var err error

	vnf.Id, err = strconv.ParseInt(vars["Vnfid"], 10, 64)

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

}
Esempio n. 3
0
func GetVnfs(w http.ResponseWriter, r *http.Request) {

	var vnfs []dbconn.Vnf
	var vnf dbconn.Vnf

	vnfs, err := vnf.Gets()
	if 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(vnfs); err != nil {
		panic(err)
	}

}
Esempio n. 4
0
func GetVnf(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)

	var vnf dbconn.Vnf
	var err error

	vnf.Id, err = strconv.ParseInt(vars["Vnfid"], 10, 64)

	if err = vnf.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(vnf); err != nil {
		panic(err)
	}

}