HandleListUsers handles the `GET /users/` request and responds with a JSON formatted list of user names.
(c web.C, w http.ResponseWriter, r *http.Request)
| 26 | // HandleListUsers handles the `GET /users/` request and responds with a JSON formatted list |
| 27 | // of user names. |
| 28 | func (s *Server) HandleListUsers(c web.C, w http.ResponseWriter, r *http.Request) { |
| 29 | users, err := s.Store.List("/users/") |
| 30 | if err != nil { |
| 31 | s.logger.Printf("ERROR: %s", err) |
| 32 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | json.NewEncoder(w).Encode(struct { |
| 37 | Users []string `json:"users"` |
| 38 | }{Users: users}) |
| 39 | } |
| 40 | |
| 41 | // HandleGetUser handles the `GET /users/:id` request and responds with the user object in JSON |
| 42 | // format. The HashedPassword field is excluded. |