Example #1
0
func (c *TodoContext) ReadMany(rw web.ResponseWriter, req *web.Request) {
	todos := &Todos{}
	err := c.TodoService.ReadMany(todos)
	if err != nil {
		rw.WriteHeader(http.StatusInternalServerError)
		log.Panicln(err)
	}

	resp, err := json.MarshalIndent(todos, "", "    ")
	if err != nil {
		rw.WriteHeader(http.StatusInternalServerError)
		log.Panicln(err)
	}

	rw.Write(resp)
}
Example #2
0
func (c *TodoContext) Read(rw web.ResponseWriter, req *web.Request) {
	todo := &Todo{}
	result, err := c.TodoService.Read(req.PathParams["id"], todo)
	if err != nil {
		switch err.(type) {
		case RowNotFoundError:
			rw.WriteHeader(http.StatusNotFound)
		default:
			rw.WriteHeader(http.StatusInternalServerError)
			log.Panicln(err)
		}
	}

	resp, err := json.MarshalIndent(&result, "", "    ")
	if err != nil {
		rw.WriteHeader(http.StatusInternalServerError)
		log.Panicln(err)
	}

	rw.Write(resp)
}