Example #1
0
func Classify(w http.ResponseWriter, r *http.Request) {
	var task model.Task
	body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
	if err != nil {
		panic(err)
	}
	if err := r.Body.Close(); err != nil {
		panic(err)
	}
	if err := json.Unmarshal(body, &task); err != nil {
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		w.WriteHeader(422)
		if err := json.NewEncoder(w).Encode(err); err != nil {
			panic(err)
		}
	}

	model.InitStorage().SaveTask(&task)

	doc := objects.MakeDoc(task.Text)
	info := model.Info{len(doc.Tokens)}
	result := model.Result{
		Status: true, Error: "", Solution: "", Info: &info,
	}
	successJson(w, result)
}
Example #2
0
func ShowTasks(w http.ResponseWriter, r *http.Request) {
	s := model.InitStorage()
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	if err := json.NewEncoder(w).Encode(s.Tasks()); err != nil {
		panic(err)
	}

}