(w http.ResponseWriter, r *http.Request)
| 8 | ) |
| 9 | |
| 10 | func setOption(w http.ResponseWriter, r *http.Request) { |
| 11 | currentUser := helpers.GetFromContext(r, "user").(*db.User) |
| 12 | |
| 13 | if !currentUser.Admin { |
| 14 | helpers.WriteJSON(w, http.StatusForbidden, map[string]string{ |
| 15 | "error": "User must be admin", |
| 16 | }) |
| 17 | return |
| 18 | } |
| 19 | |
| 20 | var option db.Option |
| 21 | if !helpers.Bind(w, r, &option) { |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | err := helpers.Store(r).SetOption(option.Key, option.Value) |
| 26 | if err != nil { |
| 27 | helpers.WriteJSON(w, http.StatusInternalServerError, map[string]string{ |
| 28 | "error": "Can not set option", |
| 29 | }) |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | helpers.WriteJSON(w, http.StatusOK, option) |
| 34 | } |
| 35 | |
| 36 | func getOptions(w http.ResponseWriter, r *http.Request) { |
| 37 | currentUser := helpers.GetFromContext(r, "user").(*db.User) |
nothing calls this directly
no test coverage detected