use sux as router
This commit is contained in:
parent
6ba1f202d9
commit
d2e155dae4
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.23
|
||||
require (
|
||||
github.com/dchest/uniuri v1.2.0
|
||||
github.com/spf13/cobra v1.8.1
|
||||
code.icod.de/dalu/sux v1.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
||||
code.icod.de/dalu/sux v1.0.1 h1:UUlZ5VUEBMKWHfcos3rAMFHPtxSWIPrxubShoY1Ch/o=
|
||||
code.icod.de/dalu/sux v1.0.1/go.mod h1:zpXnrzoSSWNbbasEjvikz2gFh/KIKpFMVPFnPVvOTBk=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/dchest/uniuri v1.2.0 h1:koIcOUdrTIivZgSLhHQvKgqdWZq5d7KdMEWF1Ud6+5g=
|
||||
github.com/dchest/uniuri v1.2.0/go.mod h1:fSzm4SLHzNZvWLvWJew423PhAzkpNQYq+uNLq4kxhkY=
|
||||
|
Loading…
x
Reference in New Issue
Block a user