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
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
2023-06-24 19:49:51 -04:00
|
|
|
if res.StatusCode() >= 400 {
|
2022-06-04 00:05:46 -04:00
|
|
|
body := res.Body()
|
2023-06-09 00:36:49 -04:00
|
|
|
return fmt.Errorf("request %s failed: %s", c.assembleURL(path), string(body))
|
2022-06-04 00:05:46 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|