Esempio n. 1
0
func GroupPushApp(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	name := vars["name"]
	app := vars["app"]
	weights, ok := r.URL.Query()["weight"]
	if !ok || len(weights) == 0 {
		http.Error(w, "weight argument is absent", http.StatusBadRequest)
		return
	}

	weight, err := strconv.Atoi(weights[0])
	if err != nil {
		http.Error(w, "weight must be an integer value", http.StatusBadRequest)
		return
	}

	err = cocs.GroupPushApp(name, app, weight)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	fmt.Fprint(w, "OK")
}