aboutsummaryrefslogtreecommitdiff
path: root/web/request.go
blob: d51a5821d0897a1380a04e5f2bccd58d99eebede (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
}