V2bX/api/panel/utils.go

32 lines
780 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
)
// Describe return a description of the client
func (c *Client) Describe() ClientInfo {
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 {
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
}