// RedisUserWrite function func RedisUserWrite(w http.ResponseWriter, r *http.Request, params httprouter.Params) { log.Print("access to user write api of redis") id := params.ByName("id") if id == "" { log.Print("put without _id") return } log.Print("put with id") if r.Body != nil { defer r.Body.Close() body, _ := ioutil.ReadAll(r.Body) // if err := json.Unmarshal([]byte(body), &user); err != nil { // http.Error(w, err.Error(), http.StatusInternalServerError) // return // } if err := db.Write("user", id, body); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") w.Write([]byte("{\"status\":\"ok\"}")) } }
// UserPut func func UserPut(r render.Render, params martini.Params, user models.User) { if len(params) == 0 { r.JSON(400, map[string]string{"error": "Argument invalid."}) return } if err := db.Write("user:"******"id"], &user); err != nil { r.JSON(500, map[string]string{"error": err.Error()}) return } r.JSON(200, user) }