Пример #1
0
func DeleteConfiguration(w http.ResponseWriter, r *http.Request){
	body, _ := ioutil.ReadAll(r.Body)
	vars := mux.Vars(r)

	var cfg = database.Configuration{}
	json.Unmarshal(body, &cfg)


	cfg.Name = vars["name"]

	oldConfig := database.GetConfigurationByName(cfg.Name)

	cfg.ID = oldConfig.ID

	ok := cfg.DeleteConfiguration()

	if ok{
		json.NewEncoder(w).Encode(cfg)
	}else{
		json.NewEncoder(w).Encode(models.ApiError{
			Code: "error",
			Message: "Error on execute",
		})
	}


}
Пример #2
0
func CreateConfiguration(w http.ResponseWriter, r *http.Request){
	body, _ := ioutil.ReadAll(r.Body)

	var cfg = database.Configuration{}

	json.Unmarshal(body, &cfg)

	database.DB.Delete(&cfg)
	ok := cfg.SaveConfiguration()

	if ok{
		json.NewEncoder(w).Encode(cfg)
	}else{
		json.NewEncoder(w).Encode(models.ApiError{
			Code: "error",
			Message: "Error on execute",
		})
	}

}