diff options
Diffstat (limited to 'internal/admin/api_modules.go')
| -rw-r--r-- | internal/admin/api_modules.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/internal/admin/api_modules.go b/internal/admin/api_modules.go index 074eeea..1d8c25b 100644 --- a/internal/admin/api_modules.go +++ b/internal/admin/api_modules.go @@ -12,7 +12,7 @@ func (s *AdminServer) handleModules(w http.ResponseWriter, r *http.Request) { case http.MethodGet: tree, err := listYAMLTree(s.dataDir, "modules") if err != nil { - writeJSON(w, map[string]any{"error": err.Error()}) + failJSON(w, err.Error()) return } if tree == nil { @@ -22,23 +22,23 @@ func (s *AdminServer) handleModules(w http.ResponseWriter, r *http.Request) { case http.MethodPost: var m map[string]any if err := readJSON(r, &m); err != nil { - writeJSON(w, map[string]any{"error": "invalid json"}) + failJSON(w, "invalid json") return } id, ok := m["id"].(string) if !ok || strings.TrimSpace(id) == "" { - writeJSON(w, map[string]any{"error": "missing id"}) + failJSON(w, "missing id") return } delete(m, "id") path := filepath.Join(s.dataDir, "modules", id+".yaml") if _, err := os.Stat(path); err == nil { - writeJSON(w, map[string]any{"error": "module already exists"}) + failJSON(w, "module already exists") return } newContent, err := writeMapAsYAML(path, m) if err != nil { - writeJSON(w, map[string]any{"error": "write error: " + err.Error()}) + failJSON(w, "write error: "+err.Error()) return } s.undoStack.Push(ChangeDesc{ @@ -68,12 +68,12 @@ func (s *AdminServer) handleModuleByID(w http.ResponseWriter, r *http.Request) { case http.MethodGet: data, path, err := findYAMLFileInSubdirs(s.dataDir, "modules", id) if err != nil { - writeJSON(w, map[string]any{"error": "not found: " + id}) + failJSON(w, "not found: "+id) return } raw, err := yamlToMap(data) if err != nil { - writeJSON(w, map[string]any{"error": "parse error: " + err.Error()}) + failJSON(w, "parse error: "+err.Error()) return } raw["id"] = id @@ -84,7 +84,7 @@ func (s *AdminServer) handleModuleByID(w http.ResponseWriter, r *http.Request) { case http.MethodPost, http.MethodPut: var body map[string]any if err := readJSON(r, &body); err != nil { - writeJSON(w, map[string]any{"error": "invalid JSON: " + err.Error()}) + failJSON(w, "invalid JSON: "+err.Error()) return } delete(body, "id") @@ -99,7 +99,7 @@ func (s *AdminServer) handleModuleByID(w http.ResponseWriter, r *http.Request) { newContent, err := writeMapAsYAML(path, body) if err != nil { - writeJSON(w, map[string]any{"error": "write error: " + err.Error()}) + failJSON(w, "write error: "+err.Error()) return } @@ -120,12 +120,12 @@ func (s *AdminServer) handleModuleByID(w http.ResponseWriter, r *http.Request) { case http.MethodDelete: _, path, err := findYAMLFileInSubdirs(s.dataDir, "modules", id) if err != nil { - writeJSON(w, map[string]any{"error": "not found: " + id}) + failJSON(w, "not found: "+id) return } oldContent, _ := snapshotFile(path) if err := os.Remove(path); err != nil { - writeJSON(w, map[string]any{"error": "delete error: " + err.Error()}) + failJSON(w, "delete error: "+err.Error()) return } s.undoStack.Push(ChangeDesc{ |
