forked from michaelklishin/rabbit-hole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_parameters.go
97 lines (77 loc) · 2.14 KB
/
global_parameters.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package rabbithole
import (
"encoding/json"
"net/http"
"net/url"
)
// GlobalRuntimeParameter represents a vhost-scoped parameter.
// Value is interface{} to support creating parameters directly from types such as
// FederationUpstream and ShovelInfo.
type GlobalRuntimeParameter struct {
Name string `json:"name"`
Value interface{} `json:"value"`
}
//
// GET /api/global-parameters
//
// ListGlobalParameters returns a list of all global parameters.
func (c *Client) ListGlobalParameters() (params []GlobalRuntimeParameter, err error) {
req, err := newGETRequest(c, "global-parameters")
if err != nil {
return []GlobalRuntimeParameter{}, err
}
if err = executeAndParseRequest(c, req, ¶ms); err != nil {
return []GlobalRuntimeParameter{}, err
}
return params, nil
}
//
// GET /api/global-parameters/name
//
// GetGlobalParameter returns information about a global parameter.
func (c *Client) GetGlobalParameter(name string) (p *GlobalRuntimeParameter, err error) {
req, err := newGETRequest(c, "global-parameters/"+url.PathEscape(name))
if err != nil {
return nil, err
}
if err = executeAndParseRequest(c, req, &p); err != nil {
return nil, err
}
return p, nil
}
//
// PUT /api/global-parameters/name/{value}
//
// PutRuntimeParameter creates or updates a runtime parameter.
func (c *Client) PutGlobalParameter(name string, value interface{}) (res *http.Response, err error) {
p := GlobalRuntimeParameter{
Name: name,
Value: value,
}
body, err := json.Marshal(p)
if err != nil {
return nil, err
}
req, err := newRequestWithBody(c, "PUT", "global-parameters/"+url.PathEscape(name), body)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
return res, nil
}
//
// DELETE /api/global-parameters/name
//
// DeleteRuntimeParameter removes a runtime parameter.
func (c *Client) DeleteGlobalParameter(name string) (res *http.Response, err error) {
req, err := newRequestWithBody(c, "DELETE", "global-parameters/"+url.PathEscape(name), nil)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
return res, nil
}