use sux as router
This commit is contained in:
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user