43 lines
610 B
Go
43 lines
610 B
Go
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))
|
|
}))
|
|
}
|