]> Cypherpunks repositories - gocheese.git/commitdiff
Simplify with CutPrefix master
authorSergey Matveev <stargrave@stargrave.org>
Sun, 13 Jul 2025 07:08:12 +0000 (10:08 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 13 Jul 2025 07:08:12 +0000 (10:08 +0300)
main.go

diff --git a/main.go b/main.go
index c987738db101e216dfd779091768d3714fe4681a..a9351c8d333e6b7047e002cd4d32592c7d82937b 100644 (file)
--- 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
        switch r.Method {
        case "GET":
                var path string
+               var found bool
                var autorefresh 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)
                        autorefresh = true
                } else {
                        http.Error(w, "unknown action", http.StatusBadRequest)