Esempio n. 1
0
func ApplicationStart(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	name := r.FormValue("name")
	profile := r.FormValue("profile")

	if len(name) == 0 || len(profile) == 0 {
		http.Error(w, "name or profile wasn't specified", http.StatusInternalServerError)
		return
	}

	stream, err := cocs.ApplicationStart(name, profile)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if f, ok := w.(http.Flusher); !ok {
		for {
			var p []byte
			_, err := stream.Read(p)
			fmt.Println(p, err)
			if err != nil {
				break
			}
			w.Write(p)
			f.Flush()
		}
	} else {
		body, _ := ioutil.ReadAll(stream)
		fmt.Fprintf(w, "%s", body)
	}
}