feat: support 1panel v2

This commit is contained in:
Fu Diwei
2025-05-16 18:57:39 +08:00
parent 06fd95782a
commit fd875feef3
18 changed files with 143 additions and 45 deletions

View File

@@ -14,19 +14,25 @@ import (
)
type Client struct {
apiHost string
apiKey string
apiHost string
apiVersion string
apiKey string
client *resty.Client
}
func NewClient(apiHost, apiKey string) *Client {
func NewClient(apiHost, apiVersion, apiKey string) *Client {
client := resty.New()
if apiVersion == "" {
apiVersion = "v1"
}
return &Client{
apiHost: strings.TrimRight(apiHost, "/"),
apiKey: apiKey,
client: client,
apiHost: strings.TrimRight(apiHost, "/"),
apiVersion: apiVersion,
apiKey: apiKey,
client: client,
}
}
@@ -49,7 +55,7 @@ func (c *Client) generateToken(timestamp string) string {
func (c *Client) sendRequest(method string, path string, params interface{}) (*resty.Response, error) {
req := c.client.R()
req.Method = method
req.URL = c.apiHost + "/api/v1" + path
req.URL = c.apiHost + "/api/" + c.apiVersion + path
if strings.EqualFold(method, http.MethodGet) {
qs := make(map[string]string)
if params != nil {