-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lmbsog0
committed
Jul 11, 2021
1 parent
9061c40
commit ff52d0a
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package rabbithole | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
// VhostLimitsValue are properties used to modify virtual hosts limits. | ||
type VhostLimitsValue struct { | ||
// Maximum number of connections | ||
MaxConnections int `json:"max-connections"` | ||
// Maximum number of queues | ||
MaxQueues int `json:"max-queues"` | ||
} | ||
|
||
type VhostLimitsInfo struct { | ||
Vhost string `json:"vhost"` | ||
Value VhostLimitsValue `json:"value"` | ||
} | ||
|
||
type VhostLimitsMaxConnections struct { | ||
Value int `json:"value"` | ||
} | ||
|
||
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 | ||
} | ||
|
||
func (c *Client) PutVhostLimitsMaxConnections(vhostname string, maxConnections int) (res *http.Response, err error) { | ||
body, err := json.Marshal(VhostLimitsMaxConnections{Value: maxConnections}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req, err := newRequestWithBody(c, "PUT", "vhost-limits/"+url.PathEscape(vhostname)+"/max-connections", body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res, err = executeRequest(c, req); err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func (c *Client) DeleteVhostLimitsMaxConnections(vhostname string) (res *http.Response, err error) { | ||
req, err := newRequestWithBody(c, "DELETE", "vhost-limits/"+url.PathEscape(vhostname)+"/max-connections", nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res, err = executeRequest(c, req); err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |