From 69cee328e77ff41adfa9e2022b2b51ac429c1bc6 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Fri, 20 May 2022 17:09:39 -0400 Subject: [PATCH] twitch: fix web server --- plugins/twitch/twitch.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/twitch/twitch.go b/plugins/twitch/twitch.go index 3f42ab3..92537bb 100644 --- a/plugins/twitch/twitch.go +++ b/plugins/twitch/twitch.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/go-chi/chi/v5" "io/ioutil" "net/http" "net/url" @@ -11,7 +12,6 @@ import ( "text/template" "time" - "github.com/go-chi/chi/v5" "github.com/rs/zerolog/log" "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" @@ -87,20 +87,19 @@ func New(b bot.Bot) *TwitchPlugin { func (p *TwitchPlugin) registerWeb() { r := chi.NewRouter() - r.HandleFunc("/", p.serveStreaming) + r.HandleFunc("/{user}", p.serveStreaming) p.bot.RegisterWeb(r, "/isstreaming") } func (p *TwitchPlugin) serveStreaming(w http.ResponseWriter, r *http.Request) { - pathParts := strings.Split(r.URL.Path, "/") - if len(pathParts) != 3 { + userName := chi.URLParam(r, "user") + if userName == "" { fmt.Fprint(w, "User not found.") return } - twitcher := p.twitchList[pathParts[2]] + twitcher := p.twitchList[userName] if twitcher == nil { - fmt.Fprint(w, "User not found.") return }