aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_modules.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-16 17:05:17 -0400
committerhistoria <[not public]>2026-09-16 17:05:17 -0400
commit1dad15698845d370e998f7cc5feb8aece3fab58f (patch)
tree8d58058782de9f422573e1f8efd5d130ce7d1ce9 /internal/admin/api_modules.go
parenta6cf03a6ae98e4fb675da25046d148e92bcf7206 (diff)
downloadthehouseoficarus-1dad15698845d370e998f7cc5feb8aece3fab58f.tar.gz
refactor: remove dead code, consolidate save/error handling, add lint gate
Diffstat (limited to 'internal/admin/api_modules.go')
-rw-r--r--internal/admin/api_modules.go22
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{