V2bX/api/panel/utils.go

27 lines
589 B
Go
Raw Normal View History

package panel
2022-06-04 00:05:46 -04:00
import (
"fmt"
"github.com/go-resty/resty/v2"
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 {
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
}