From: Sergey Matveev Date: Sun, 13 Jul 2025 07:08:12 +0000 (+0300) Subject: Simplify with CutPrefix X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=HEAD;p=gocheese.git Simplify with CutPrefix --- diff --git a/main.go b/main.go index c987738..a9351c8 100644 --- a/main.go +++ b/main.go @@ -92,11 +92,13 @@ func handler(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": var path string + var found bool var autorefresh bool - if strings.HasPrefix(r.URL.Path, *NoRefreshURLPath) { - path = strings.TrimPrefix(r.URL.Path, *NoRefreshURLPath) - } else if strings.HasPrefix(r.URL.Path, *RefreshURLPath) { - path = strings.TrimPrefix(r.URL.Path, *RefreshURLPath) + path, found = strings.CutPrefix(r.URL.Path, *NoRefreshURLPath) + if !found { + path, found = strings.CutPrefix(r.URL.Path, *RefreshURLPath) + } + if found { autorefresh = true } else { http.Error(w, "unknown action", http.StatusBadRequest)