func UpdateUser(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) uid, _ := strconv.ParseInt(vars["Userid"], 10, 64) var user dbconn.User if err := user.Parse(w, r); err != nil { http.Error(w, err.Error(), 500) return } if uid != user.Id { err := fmt.Errorf("Error: Userid mismatch") http.Error(w, err.Error(), 500) return } if err := user.Update(); err != nil { http.Error(w, err.Error(), 500) return } w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusCreated) if err := json.NewEncoder(w).Encode(user); err != nil { panic(err) } }
func DeleteUser(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) var user dbconn.User //var err error user.Id, _ = strconv.ParseInt(vars["Userid"], 10, 64) if err := user.Delete(); err != nil { http.Error(w, err.Error(), 500) return } }
func GetUser(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) var user dbconn.User //var err error user.Id, _ = strconv.ParseInt(vars["Userid"], 10, 64) if err := user.Get(); err != nil { http.Error(w, err.Error(), 500) return } w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusCreated) if err := json.NewEncoder(w).Encode(user); err != nil { panic(err) } }
func AddUser(w http.ResponseWriter, r *http.Request) { var user dbconn.User if err := user.Parse(w, r); err != nil { http.Error(w, err.Error(), 500) return } if err := user.Add(); err != nil { http.Error(w, err.Error(), 500) return } w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusCreated) if err := json.NewEncoder(w).Encode(user); err != nil { panic(err) } }