From d06e2251a41d62e9521537685f33cef495f0d5e8 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sat, 16 Jan 2021 15:29:23 -0500 Subject: [PATCH] Separate /live and / http handlers Separate the /live and / (main) http handlers. This cleans up the related code a little bit and makes it a lot easier to follow. --- handlers.go | 20 ++++++++++++-------- main.go | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/handlers.go b/handlers.go index 89367f5..8b3ae68 100644 --- a/handlers.go +++ b/handlers.go @@ -408,7 +408,7 @@ func handlePlay(conn *rtmp.Conn) { } } -func handleDefault(w http.ResponseWriter, r *http.Request) { +func handleLive(w http.ResponseWriter, r *http.Request) { l.RLock() ch := channels[strings.Trim(r.URL.Path, "/")] l.RUnlock() @@ -426,12 +426,16 @@ func handleDefault(w http.ResponseWriter, r *http.Request) { avutil.CopyFile(muxer, cursor) } else { - if r.URL.Path != "/" { - // not really an error for the server, but for the client. - common.LogInfoln("[http 404] ", r.URL.Path) - http.NotFound(w, r) - } else { - handleIndexTemplate(w, r) - } + + } +} + +func handleDefault(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + // not really an error for the server, but for the client. + common.LogInfoln("[http 404] ", r.URL.Path) + http.NotFound(w, r) + } else { + handleIndexTemplate(w, r) } } diff --git a/main.go b/main.go index 2c585d5..ca383c5 100644 --- a/main.go +++ b/main.go @@ -145,6 +145,7 @@ func startServer() { http.HandleFunc("/help", handleHelpTemplate) http.HandleFunc("/emotes", handleEmoteTemplate) + http.HandleFunc("/live", handleLive) http.HandleFunc("/", handleDefault) err := http.ListenAndServe(addr, nil)