can redir, save data.yaml to image
This commit is contained in:
22
srv/main.go
22
srv/main.go
@@ -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))
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user