data.yaml

This commit is contained in:
Bel LaPointe
2025-10-05 10:44:09 -06:00
parent 5e48c96148
commit 3c60633723
5 changed files with 67 additions and 0 deletions

42
srv/main.go Normal file
View File

@@ -0,0 +1,42 @@
package main
import (
"net/http"
"os"
"gopkg.in/yaml.v3"
)
func main() {
if err := run(); err != nil {
panic(err)
}
}
func run() error {
f := os.Args[1]
b, err := os.ReadFile(f)
if err != nil {
return err
}
var data struct {
Routes map[string]string
}
if err := yaml.Unmarshal(b, &data); err != nil {
return err
}
return http.ListenAndServe(":3001", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
k := r.URL.Path
v, ok := data.Routes[k]
if !ok {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(v))
}))
}