forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_helpers.go
50 lines (40 loc) · 992 Bytes
/
url_helpers.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package strategy
import (
"net/url"
"path"
"strconv"
)
type params struct {
resultsPerPage int64
orderDirection string
q map[string]string
recursive bool
inlineRelationsDepth int64
}
func v2(segments ...string) string {
segments = append([]string{"/v2"}, segments...)
return path.Join(segments...)
}
func buildURL(path string, params params) string {
query := url.Values{}
if params.inlineRelationsDepth != 0 {
query.Set("inline-relations-depth", strconv.FormatInt(params.inlineRelationsDepth, 10))
}
if params.resultsPerPage != 0 {
query.Set("results-per-page", strconv.FormatInt(params.resultsPerPage, 10))
}
if params.orderDirection != "" {
query.Set("order-direction", params.orderDirection)
}
if params.q != nil {
q := ""
for key, value := range params.q {
q += key + ":" + value
}
query.Set("q", q)
}
if params.recursive {
query.Set("recursive", "true")
}
return path + "?" + query.Encode()
}