Пример #1
0
func (s *TaskServices) addTask(w http.ResponseWriter, r *http.Request) {
	decoder := json.NewDecoder(r.Body)
	var taskJson map[string]*json.RawMessage

	err := decoder.Decode(&taskJson)

	if err != nil {
		SendJsonErrorResponse(w, &taskJson, err.Error())
		return
	}

	task := api.ConvertTask(taskJson)

	_, ok := task[db.REQUEST_ADDRESS]

	if !ok {
		task[db.REQUEST_ADDRESS] = r.Host
	}

	timestamp, e := s.api.SaveTask(task)

	if e != nil {
		SendJsonErrorResponse(w, &taskJson, e.Error())
		return
	}

	SendJsonResponse(w, timestamp, nil)
}
Пример #2
0
func ParseTask(message []byte) db.Task {
	var taskJson map[string]*json.RawMessage

	err := json.Unmarshal(message, &taskJson)

	if err != nil {
		fmt.Println("Error parsing task json %s", err)
		return make(db.Task)
	}

	return api.ConvertTask(taskJson)
}