(w http.ResponseWriter, r *http.Request)
| 286 | } |
| 287 | |
| 288 | func (h *httpHandlers) handleConfigPost(w http.ResponseWriter, r *http.Request) { |
| 289 | body, err := io.ReadAll(r.Body) |
| 290 | if err != nil { |
| 291 | http.Error(w, fmt.Sprintf("failed to read request body: %v", err), http.StatusBadRequest) |
| 292 | return |
| 293 | } |
| 294 | |
| 295 | var configData map[string]any |
| 296 | if err := json.Unmarshal(body, &configData); err != nil { |
| 297 | http.Error(w, fmt.Sprintf("failed to parse JSON: %v", err), http.StatusBadRequest) |
| 298 | return |
| 299 | } |
| 300 | |
| 301 | var failedKeys []string |
| 302 | for key, value := range configData { |
| 303 | atomName := "$config." + key |
| 304 | if err := h.Client.Root.SetAtomVal(atomName, value); err != nil { |
| 305 | failedKeys = append(failedKeys, key) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | w.Header().Set("Content-Type", "application/json") |
| 310 | |
| 311 | var response map[string]any |
| 312 | if len(failedKeys) > 0 { |
| 313 | response = map[string]any{ |
| 314 | "error": fmt.Sprintf("Failed to update keys: %s", strings.Join(failedKeys, ", ")), |
| 315 | } |
| 316 | } else { |
| 317 | response = map[string]any{ |
| 318 | "success": true, |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | w.WriteHeader(http.StatusOK) |
| 323 | |
| 324 | json.NewEncoder(w).Encode(response) |
| 325 | } |
| 326 | |
| 327 | func (h *httpHandlers) handleSchemas(w http.ResponseWriter, r *http.Request) { |
| 328 | defer func() { |
no test coverage detected