use sux as router

This commit is contained in:
2024-12-31 13:22:32 +01:00
parent 6ba1f202d9
commit d2e155dae4
3 changed files with 10 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"net/http"
"os"
"code.icod.de/dalu/sux"
"github.com/dchest/uniuri"
"github.com/spf13/cobra"
)
@ -21,13 +22,18 @@ var simpleCmd = &cobra.Command{
pass = uniuri.New()
}
fmt.Println("Stream password:", pass)
return http.ListenAndServe(fmt.Sprintf("127.0.0.1:%s", port), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Stream port:", port)
r := sux.New()
r.POST("/auth", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.FormValue("name") == pass {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(http.StatusForbidden)
}
}))
addr := fmt.Sprintf("127.0.0.1:%s", port)
fmt.Println("Listening on addr:", addr)
return http.ListenAndServe(addr, r)
},
}