HandleGetUser handles the `GET /users/:id` request and responds with the user object in JSON format. The HashedPassword field is excluded.
(c web.C, w http.ResponseWriter, r *http.Request)
| 41 | // HandleGetUser handles the `GET /users/:id` request and responds with the user object in JSON |
| 42 | // format. The HashedPassword field is excluded. |
| 43 | func (s *Server) HandleGetUser(c web.C, w http.ResponseWriter, r *http.Request) { |
| 44 | user := User{} |
| 45 | err := s.Store.Get(fmt.Sprintf("/users/%s", c.URLParams["id"]), &user) |
| 46 | if err != nil { |
| 47 | s.logger.Printf("ERROR: %s", err) |
| 48 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| 49 | return |
| 50 | } |
| 51 | user.HashedPassword = nil |
| 52 | json.NewEncoder(w).Encode(user) |
| 53 | } |
| 54 | |
| 55 | // HandlePutUser handles the `PUT /users/:id` request. It accepts a JSON formatted user object in |
| 56 | // the request body and stores it. If the PlaintextPassword field is present then it is hashed |