forked from michaelklishin/rabbit-hole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vhost_limits.go
86 lines (69 loc) · 2.15 KB
/
vhost_limits.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
package rabbithole
import (
"encoding/json"
"net/http"
"net/url"
)
// VhostLimitsValues are properties used to modify virtual host limits (max-connections, max-queues)
type VhostLimitsValues map[string]int
// VhostLimits are properties used to delete virtual host limits (max-connections, max-queues)
type VhostLimits []string
// VhostLimitsInfo holds information about the current virtual host limits
type VhostLimitsInfo struct {
Vhost string `json:"vhost"`
Value VhostLimitsValues `json:"value"`
}
// GetAllVhostLimits gets all virtual hosts limits.
func (c *Client) GetAllVhostLimits() (rec []VhostLimitsInfo, err error) {
req, err := newGETRequest(c, "vhost-limits")
if err != nil {
return nil, err
}
if err = executeAndParseRequest(c, req, &rec); err != nil {
return nil, err
}
return rec, nil
}
// GetVhostLimits gets a virtual host limits.
func (c *Client) GetVhostLimits(vhostname string) (rec []VhostLimitsInfo, err error) {
req, err := newGETRequest(c, "vhost-limits/"+url.PathEscape(vhostname))
if err != nil {
return nil, err
}
if err = executeAndParseRequest(c, req, &rec); err != nil {
return nil, err
}
return rec, nil
}
// PutVhostLimits puts limits of a virtual host.
func (c *Client) PutVhostLimits(vhostname string, limits VhostLimitsValues) (res *http.Response, err error) {
for limitName, limitValue := range limits {
body, err := json.Marshal(struct {
Value int `json:"value"`
}{Value: limitValue})
if err != nil {
return nil, err
}
req, err := newRequestWithBody(c, "PUT", "vhost-limits/"+url.PathEscape(vhostname)+"/"+limitName, body)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
}
return res, nil
}
// DeleteVhostLimits deletes limits of a virtual host.
func (c *Client) DeleteVhostLimits(vhostname string, limits VhostLimits) (res *http.Response, err error) {
for _, limit := range limits {
req, err := newRequestWithBody(c, "DELETE", "vhost-limits/"+url.PathEscape(vhostname)+"/"+limit, nil)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
}
return res, nil
}