Add the ability to fetch all servers, fix cpu usage leak again..

This commit is contained in:
Matthew Penner
2020-04-10 15:39:07 -06:00
parent e719c67e0b
commit 28c8f3f400
11 changed files with 87 additions and 76 deletions

View File

@@ -13,7 +13,7 @@ import (
"time"
)
// Initalizes the requester instance.
// Initializes the requester instance.
func NewRequester() *PanelRequest {
return &PanelRequest{
Response: nil,

View File

@@ -49,6 +49,30 @@ type InstallationScript struct {
Script string `json:"script"`
}
// GetAllServerConfigurations fetches configurations for all servers assigned to this node.
func (r *PanelRequest) GetAllServerConfigurations() (map[string]*ServerConfigurationResponse, *RequestError, error) {
resp, err := r.Get("/servers")
if err != nil {
return nil, nil, errors.WithStack(err)
}
defer resp.Body.Close()
r.Response = resp
if r.HasError() {
return nil, r.Error(), nil
}
res := map[string]*ServerConfigurationResponse{}
b, _ := r.ReadBody()
if err := json.Unmarshal(b, &res); err != nil {
return nil, nil, errors.WithStack(err)
}
return res, nil, nil
}
// Fetches the server configuration and returns the struct for it.
func (r *PanelRequest) GetServerConfiguration(uuid string) (*ServerConfigurationResponse, *RequestError, error) {
resp, err := r.Get(fmt.Sprintf("/servers/%s", uuid))