refactor: clean code
This commit is contained in:
25
internal/pkg/vendors/1panel-sdk/api.go
vendored
25
internal/pkg/vendors/1panel-sdk/api.go
vendored
@@ -8,44 +8,29 @@ import (
|
||||
func (c *Client) UpdateSystemSSL(req *UpdateSystemSSLRequest) (*UpdateSystemSSLResponse, error) {
|
||||
resp := &UpdateSystemSSLResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/settings/ssl/update", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SearchWebsiteSSL(req *SearchWebsiteSSLRequest) (*SearchWebsiteSSLResponse, error) {
|
||||
resp := &SearchWebsiteSSLResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/websites/ssl/search", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UploadWebsiteSSL(req *UploadWebsiteSSLRequest) (*UploadWebsiteSSLResponse, error) {
|
||||
resp := &UploadWebsiteSSLResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/websites/ssl/upload", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsConf(req *GetHttpsConfRequest) (*GetHttpsConfResponse, error) {
|
||||
resp := &GetHttpsConfResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, fmt.Sprintf("/websites/%d/https", req.WebsiteID), req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsConf(req *UpdateHttpsConfRequest) (*UpdateHttpsConfResponse, error) {
|
||||
resp := &UpdateHttpsConfResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, fmt.Sprintf("/websites/%d/https", req.WebsiteID), req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
4
internal/pkg/vendors/1panel-sdk/client.go
vendored
4
internal/pkg/vendors/1panel-sdk/client.go
vendored
@@ -77,9 +77,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("1panel api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("1panel api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("1panel api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("1panel api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
22
internal/pkg/vendors/1panel-sdk/models.go
vendored
22
internal/pkg/vendors/1panel-sdk/models.go
vendored
@@ -6,16 +6,22 @@ type BaseResponse interface {
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Code int32 `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Code *int32 `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetCode() int32 {
|
||||
return r.Code
|
||||
if r.Code != nil {
|
||||
return *r.Code
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMessage() string {
|
||||
return r.Message
|
||||
if r.Message != nil {
|
||||
return *r.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type UpdateSystemSSLRequest struct {
|
||||
@@ -38,7 +44,7 @@ type SearchWebsiteSSLRequest struct {
|
||||
|
||||
type SearchWebsiteSSLResponse struct {
|
||||
baseResponse
|
||||
Data struct {
|
||||
Data *struct {
|
||||
Items []*struct {
|
||||
ID int64 `json:"id"`
|
||||
PEM string `json:"pem"`
|
||||
@@ -50,7 +56,7 @@ type SearchWebsiteSSLResponse struct {
|
||||
CreatedAt string `json:"createdAt"`
|
||||
} `json:"items"`
|
||||
Total int32 `json:"total"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type UploadWebsiteSSLRequest struct {
|
||||
@@ -73,13 +79,13 @@ type GetHttpsConfRequest struct {
|
||||
|
||||
type GetHttpsConfResponse struct {
|
||||
baseResponse
|
||||
Data struct {
|
||||
Data *struct {
|
||||
Enable bool `json:"enable"`
|
||||
HttpConfig string `json:"httpConfig"`
|
||||
SSLProtocol []string `json:"SSLProtocol"`
|
||||
Algorithm string `json:"algorithm"`
|
||||
Hsts bool `json:"hsts"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateHttpsConfRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user