can redir, save data.yaml to image

This commit is contained in:
Bel LaPointe
2025-10-06 07:28:18 -06:00
parent 1e7adcf45c
commit 38786d3b1a
3 changed files with 39 additions and 14 deletions

View File

@@ -13,6 +13,16 @@ func main() {
}
}
type (
Data struct {
Routes map[string]Route
}
Route struct {
Body string
Redirect string
}
)
func run() error {
f := os.Args[1]
b, err := os.ReadFile(f)
@@ -20,9 +30,9 @@ func run() error {
return err
}
var data struct {
Routes map[string]string
type Route struct {
}
var data Data
if err := yaml.Unmarshal(b, &data); err != nil {
return err
}
@@ -36,7 +46,11 @@ func run() error {
return
}
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(v))
if u := v.Redirect; u != "" {
http.Redirect(w, r, u, http.StatusSeeOther)
} else {
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(v.Body))
}
}))
}