aboutsummaryrefslogtreecommitdiff
path: root/web/request.go
diff options
context:
space:
mode:
Diffstat (limited to 'web/request.go')
-rw-r--r--web/request.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/web/request.go b/web/request.go
new file mode 100644
index 0000000..d51a582
--- /dev/null
+++ b/web/request.go
@@ -0,0 +1,36 @@
+package web
+
+import (
+ "fmt"
+ "net/http"
+ "strings"
+)
+
+func queryOrDefault(r *http.Request, key, fallback string) string {
+ if value := r.URL.Query().Get(key); value != "" {
+ return value
+ }
+ return fallback
+}
+
+func syncNotice(r *http.Request) string {
+ imported := r.URL.Query().Get("imported")
+ if imported == "" {
+ return ""
+ }
+ return fmt.Sprintf("Sync complete: %s imported, %s skipped.", imported, r.URL.Query().Get("skipped"))
+}
+
+func rideDetailNotice(r *http.Request) string {
+ if r.URL.Query().Get("official_climb") == "created" {
+ return "Official climb saved and matched to this ride by coordinates."
+ }
+ return ""
+}
+
+func safeReturnTo(value string) string {
+ if value == "" || !strings.HasPrefix(value, "/") || strings.HasPrefix(value, "//") {
+ return "/sync"
+ }
+ return value
+}