Initial commit

This commit is contained in:
Mester Gábor
2026-03-19 07:12:03 +01:00
commit 2dd6519168
25 changed files with 3645 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
package storage
import (
"os"
"path/filepath"
"strings"
"gopkg.in/yaml.v3"
)
// SaveRequest writes rf to .greq/requests/<folder>/<slug>.yaml.
// folder may be empty (places the file directly in requests/).
func SaveRequest(rf RequestFile, folder string) (string, error) {
dir := filepath.Join(RootDir, "requests")
if folder != "" {
dir = filepath.Join(dir, folder)
}
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", err
}
slug := strings.ToLower(strings.ReplaceAll(rf.Name, " ", "_"))
slug = strings.Map(func(r rune) rune {
if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '_' || r == '-' {
return r
}
return '_'
}, slug)
path := filepath.Join(dir, slug+".yaml")
data, err := yaml.Marshal(&rf)
if err != nil {
return "", err
}
return path, os.WriteFile(path, data, 0o644)
}