Пример #1
0
func unmarshalTask(request *http.Request) (models.Task, error) {
	var taskModel models.Task

	//grab posted task
	task, err := ioutil.ReadAll(io.LimitReader(request.Body, 1048576))
	services.FailOnError(err, "Invalid post request")

	if err = request.Body.Close(); err != nil {
		services.FailOnError(err, "An unknown error has occured")
	}
	err = json.Unmarshal(task, &taskModel)
	services.FailOnError(err, "Invalid request 123")
	return taskModel, nil
}
Пример #2
0
//GetUrl redirects to the longUrl given the passed in shortUrl. Also inserts a visit record.
func PostTaskUpdate(responseWriter http.ResponseWriter, request *http.Request) {

	// get request and unmarshal it
	task, err := unmarshalTask(request)
	services.FailOnError(err, "Cannot unmarshal json")
	log.Printf("Task: %v", task)
	// send unmarshalled task to database
	services.UpdateTask(task)
	// error handling

	// on success send to Rabbit
	services.SendUpdatesToRabbit(task)

	http.Error(responseWriter, "made it", http.StatusOK)

}