-
Notifications
You must be signed in to change notification settings - Fork 28
/
utils.go
43 lines (35 loc) · 1.04 KB
/
utils.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package pages
import (
"fmt"
"net/url"
)
func makeBaseTemplateSettings(global globalSettings) func(string, interface{}) baseTemplateSettings {
return func(pageName string, arguments interface{}) baseTemplateSettings {
return baseTemplateSettings{
globalSettings: global,
PageName: pageName,
Arguments: arguments,
}
}
}
// addURLParams adds all parameters defined by "key" "value" to the url url
func addURLParams(baseUrl string, keysAndValues ...interface{}) string {
u, err := url.Parse(baseUrl)
if err != nil {
panic(fmt.Sprintf("unable to parse url %s: %v", baseUrl, err))
}
if (len(keysAndValues) % 2) != 0 {
panic("odd number of key value pairs")
}
q := u.Query()
for i := 0; i < len(keysAndValues); i = i + 2 {
key := fmt.Sprintf("%v", keysAndValues[i])
value := fmt.Sprintf("%v", keysAndValues[i+1])
q.Set(key, value)
}
u.RawQuery = q.Encode()
return u.String()
}