2022-08-16 01:04:33 -04:00
|
|
|
package panel
|
2022-06-04 00:05:46 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/go-resty/resty/v2"
|
2022-12-18 10:31:06 -05:00
|
|
|
path2 "path"
|
2022-06-04 00:05:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Describe return a description of the client
|
|
|
|
func (c *Client) Describe() ClientInfo {
|
2022-12-18 10:31:06 -05:00
|
|
|
return ClientInfo{APIHost: c.APIHost, NodeID: c.NodeId, Key: c.Key, NodeType: c.NodeType}
|
2022-06-04 00:05:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debug set the client debug for client
|
|
|
|
func (c *Client) Debug() {
|
|
|
|
c.client.SetDebug(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) assembleURL(path string) string {
|
2022-12-18 10:31:06 -05:00
|
|
|
return path2.Join(c.APIHost + path)
|
2022-06-04 00:05:46 -04:00
|
|
|
}
|
|
|
|
func (c *Client) checkResponse(res *resty.Response, path string, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("request %s failed: %s", c.assembleURL(path), err)
|
|
|
|
}
|
2022-12-23 13:44:09 -05:00
|
|
|
if res.StatusCode() != 200 {
|
2022-06-04 00:05:46 -04:00
|
|
|
body := res.Body()
|
|
|
|
return fmt.Errorf("request %s failed: %s, %s", c.assembleURL(path), string(body), err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|