diff options
| author | historia <[not public]> | 2026-06-29 22:31:11 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-29 22:31:11 -0400 |
| commit | 069d3c1c81d71042706372df153254487a765dfc (patch) | |
| tree | d83a4a3954d2b8304f49d83e365f4c2b075b91eb /internal/admin/api_helpers.go | |
| parent | 6c5271fb085b4571a10f106391974c249cd84317 (diff) | |
| download | thehouseoficarus-069d3c1c81d71042706372df153254487a765dfc.tar.gz | |
feat: wip web admin for mapping and crud
Diffstat (limited to 'internal/admin/api_helpers.go')
| -rw-r--r-- | internal/admin/api_helpers.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/admin/api_helpers.go b/internal/admin/api_helpers.go new file mode 100644 index 0000000..78e59d4 --- /dev/null +++ b/internal/admin/api_helpers.go @@ -0,0 +1,31 @@ +package admin + +import ( + "bytes" + "os" + + "gopkg.in/yaml.v3" +) + +func yamlToMap(data []byte) (map[string]any, error) { + var m map[string]any + if err := yaml.Unmarshal(data, &m); err != nil { + return nil, err + } + return m, nil +} + +func writeMapAsYAML(path string, m map[string]any) ([]byte, error) { + var buf bytes.Buffer + enc := yaml.NewEncoder(&buf) + enc.SetIndent(2) + if err := enc.Encode(m); err != nil { + return nil, err + } + enc.Close() + content := buf.Bytes() + if err := os.WriteFile(path, content, 0644); err != nil { + return nil, err + } + return content, nil +} |
