Example #1
0
func AddRepo(w http.ResponseWriter, r *http.Request) {
	body, _ := ioutil.ReadAll(r.Body)
	repo := database.Repository{}
	json.Unmarshal(body, &repo)

	repo.SaveRepository()

	json.NewEncoder(w).Encode(repo)

}
Example #2
0
func DeleteRepo(w http.ResponseWriter, r *http.Request) {
	body, _ := ioutil.ReadAll(r.Body)
	vars := mux.Vars(r)

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

	cfg.Name = vars["name"]

	oldConfig := database.GetRepositoryByName(cfg.Name)

	cfg.ID = oldConfig.ID

	ok := cfg.DeleteRepository()

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