refactor: clean code

This commit is contained in:
Fu Diwei
2026-07-21 17:01:52 +08:00
parent 888012f2e2
commit c3f529eaa0
59 changed files with 209 additions and 181 deletions
+3 -3
View File
@@ -76,6 +76,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -84,9 +87,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -77,6 +77,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -85,9 +88,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的官方 SDK:`github.com/aliyun/alibabacloud-oss-go-sdk-v2`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1341](https://github.com/certimate-go/certimate/pull/1341)。
@@ -35,7 +35,7 @@ func (c *Client) PutBucketCname(req *PutCnameRequest) (*PutCnameResponse, error)
}
func (c *Client) PutBucketCnameWithContext(ctx context.Context, req *PutCnameRequest) (*PutCnameResponse, error) {
httpreq, err := c.newRequest(http.MethodPost, "/?cname&comp=add", fmt.Sprintf("/%s/", c.bucket), req)
httpreq, err := c.newRequest(http.MethodPost, "/?cname&comp=add", req, fmt.Sprintf("/%s/", c.bucket))
if err != nil {
return nil, err
} else {
+6 -6
View File
@@ -79,7 +79,7 @@ func (c *Client) SetTimeout(timeout time.Duration) *Client {
return c
}
func (c *Client) newRequest(method string, path string, resource string, params any) (*resty.Request, error) {
func (c *Client) newRequest(method string, path string, params any, ossResource string) (*resty.Request, error) {
if method == "" {
return nil, fmt.Errorf("sdkerr: unset method")
}
@@ -115,8 +115,12 @@ func (c *Client) newRequest(method string, path string, resource string, params
req.QueryParam = requestUrl.Query()
req.SetHeader("Content-MD5", payloadMd5Encoded)
req.SetHeader("Content-Type", contentType)
req.SetHeader("X-API-Resource", resource)
req.SetHeader("X-API-Resource", ossResource)
req.SetBody(payloadStr)
// WARN:
// DO NOT CALL `req.SetBody` or `req.SetFormData` AGAIN! USE `newRequest` INSTEAD.
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -125,10 +129,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetBody` or `req.SetFormData` HERE! USE `newRequest` INSTEAD.
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -66,6 +66,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -74,9 +77,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+4 -4
View File
@@ -106,6 +106,10 @@ func (c *Client) newRequest(method string, path string, params any) (*resty.Requ
req.Method = method
req.URL = path
req.SetFormData(paramsMap)
// WARN:
// DO NOT CALL `req.SetBody` or `req.SetFormData` AGAIN! USE `newRequest` INSTEAD.
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -114,10 +118,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetBody` or `req.SetFormData` HERE! USE `newRequest` INSTEAD.
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -4
View File
@@ -143,6 +143,9 @@ func (c *Client) newRequest(method string, path string, params any, multipart bo
req.SetFormData(paramsMap)
}
// WARN:
// DO NOT CALL `req.SetBody` or `req.SetFormData` AGAIN! USE `newRequest` INSTEAD.
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -151,10 +154,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetBody` or `req.SetFormData` HERE! USE `newRequest` INSTEAD.
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -76,6 +76,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -84,9 +87,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -51,6 +51,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -59,9 +62,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -70,6 +70,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -78,9 +81,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的官方 SDK:`github.com/cloudflare/cloudflare-go`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1330](https://github.com/certimate-go/certimate/pull/1330)。
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
@@ -40,7 +40,8 @@ func (c *Client) DnsCreateRecordWithContext(ctx context.Context, domainId string
return nil, err
}
httpreq, err := c.newRequest(http.MethodPost, fmt.Sprintf("%s/v1/domains/%s/records", dnsBaseURL, url.PathEscape(domainId)))
path := dnsBaseURL + fmt.Sprintf("/v1/domains/%s/records", url.PathEscape(domainId))
httpreq, err := c.newRequest(http.MethodPost, path)
if err != nil {
return nil, err
} else {
@@ -27,7 +27,8 @@ func (c *Client) DnsDeleteRecordWithContext(ctx context.Context, domainId string
return nil, err
}
httpreq, err := c.newRequest(http.MethodDelete, fmt.Sprintf("%s/v1/domains/%s/records/%s", dnsBaseURL, url.PathEscape(domainId), url.PathEscape(recordId)))
path := dnsBaseURL + fmt.Sprintf("/v1/domains/%s/records/%s", url.PathEscape(domainId), url.PathEscape(recordId))
httpreq, err := c.newRequest(http.MethodDelete, path)
if err != nil {
return nil, err
} else {
@@ -2,7 +2,6 @@ package v3
import (
"context"
"fmt"
"net/http"
qs "github.com/google/go-querystring/query"
@@ -31,7 +30,8 @@ func (c *Client) DnsGetDomainsListWithContext(ctx context.Context, req *DnsGetDo
return nil, err
}
httpreq, err := c.newRequest(http.MethodGet, fmt.Sprintf("%s/v1/domains", dnsBaseURL))
path := dnsBaseURL + "/v1/domains"
httpreq, err := c.newRequest(http.MethodGet, path)
if err != nil {
return nil, err
} else {
+4 -4
View File
@@ -89,6 +89,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -97,9 +100,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
@@ -143,7 +143,7 @@ func (c *Client) ensureToken(ctx context.Context) error {
return nil
}
httpreq, err := c.newRequest(http.MethodPost, fmt.Sprintf("%s/v3/auth/tokens", identityBaseURL))
httpreq, err := c.newRequest(http.MethodPost, identityBaseURL+"/v3/auth/tokens")
if err != nil {
return err
} else {
+3 -3
View File
@@ -68,6 +68,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -76,9 +79,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -71,6 +71,9 @@ func (c *Client) NewRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -79,9 +82,6 @@ func (c *Client) DoRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5 -5
View File
@@ -108,7 +108,7 @@ func (c *Client) buildServerlessClientInfo(appId string) (_clientInfo map[string
}, nil
}
func (c *Client) buildServerlessPayloadInfo(appId, spaceId, target, method, action string, params, data interface{}) (map[string]any, error) {
func (c *Client) buildServerlessPayloadInfo(appId, spaceId, target, method, action string, params, data any) (map[string]any, error) {
clientInfo, err := c.buildServerlessClientInfo(appId)
if err != nil {
return nil, err
@@ -157,7 +157,7 @@ func (c *Client) buildServerlessPayloadInfo(appId, spaceId, target, method, acti
return payload, nil
}
func (c *Client) invokeServerless(ctx context.Context, endpoint, clientSecret, appId, spaceId, target, method, action string, params, data interface{}) (*resty.Response, error) {
func (c *Client) invokeServerless(ctx context.Context, endpoint, clientSecret, appId, spaceId, target, method, action string, params, data any) (*resty.Response, error) {
if endpoint == "" {
return nil, fmt.Errorf("sdkerr: bad request: endpoint cannot be empty")
}
@@ -191,7 +191,7 @@ func (c *Client) invokeServerless(ctx context.Context, endpoint, clientSecret, a
return resp, nil
}
func (c *Client) invokeServerlessWithResult(ctx context.Context, endpoint, clientSecret, appId, spaceId, target, method, action string, params, data interface{}, result sdkResponse) error {
func (c *Client) invokeServerlessWithResult(ctx context.Context, endpoint, clientSecret, appId, spaceId, target, method, action string, params, data any, result sdkResponse) error {
resp, err := c.invokeServerless(ctx, endpoint, clientSecret, appId, spaceId, target, method, action, params, data)
if err != nil {
if resp != nil {
@@ -209,7 +209,7 @@ func (c *Client) invokeServerlessWithResult(ctx context.Context, endpoint, clien
return nil
}
func (c *Client) sendRequest(ctx context.Context, method string, path string, params interface{}) (*resty.Response, error) {
func (c *Client) sendRequest(ctx context.Context, method string, path string, params any) (*resty.Response, error) {
req := c.rcForApiUser.R().
SetContext(ctx)
if strings.EqualFold(method, http.MethodGet) {
@@ -240,7 +240,7 @@ func (c *Client) sendRequest(ctx context.Context, method string, path string, pa
return resp, nil
}
func (c *Client) sendRequestWithResult(ctx context.Context, method string, path string, params interface{}, result sdkResponse) error {
func (c *Client) sendRequestWithResult(ctx context.Context, method string, path string, params any, result sdkResponse) error {
resp, err := c.sendRequest(ctx, method, path, params)
if err != nil {
if resp != nil {
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -66,6 +66,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -74,9 +77,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -66,6 +66,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -74,9 +77,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -97,6 +97,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -105,9 +108,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -97,6 +97,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -105,9 +108,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的官方 SDK:`github.com/huaweicloud/huaweicloud-sdk-go-v3`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1341](https://github.com/certimate-go/certimate/pull/1341)。
+4 -4
View File
@@ -111,6 +111,10 @@ func (c *Client) newRequest(method string, path string, params any) (*resty.Requ
req.SetHeader("Content-MD5", payloadMd5Encoded)
req.SetHeader("Content-Type", contentType)
req.SetBody(payloadStr)
// WARN:
// DO NOT CALL `req.SetBody` or `req.SetFormData` AGAIN! USE `newRequest` INSTEAD.
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -119,10 +123,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetBody` or `req.SetFormData` HERE! USE `newRequest` INSTEAD.
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的官方 SDK:`github.com/kong/go-kong`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1330](https://github.com/certimate-go/certimate/pull/1330)。
+3 -3
View File
@@ -71,6 +71,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -79,9 +82,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的官方 SDK:`github.com/KscSDK/ksc-sdk-go/service/cdnv1`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1341](https://github.com/certimate-go/certimate/pull/1341)。
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的官方 SDK:`github.com/KscSDK/ksc-sdk-go/service/kcm`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1341](https://github.com/certimate-go/certimate/pull/1341)。
+3 -4
View File
@@ -107,6 +107,9 @@ func (c *Client) NewRequest(method string, path string, params any) (*resty.Requ
req.SetBody(paramsMap)
}
// WARN:
// DO NOT CALL `req.SetBody` or `req.SetFormData` AGAIN! USE `newRequest` INSTEAD.
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -115,10 +118,6 @@ func (c *Client) DoRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetBody` or `req.SetFormData` HERE! USE `newRequest` INSTEAD.
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -85,6 +85,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -93,9 +96,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -87,6 +87,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -95,9 +98,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的官方 SDK:`github.com/linode/linodego`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1330](https://github.com/certimate-go/certimate/pull/1330)。
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -77,6 +77,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -85,9 +88,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -86,6 +86,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -94,9 +97,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的社区 SDK:`github.com/luthermonson/go-proxmox`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1330](https://github.com/certimate-go/certimate/pull/1330)。
+3 -3
View File
@@ -69,6 +69,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -77,9 +80,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -66,6 +66,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -74,9 +77,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -52,6 +52,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -60,9 +63,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -80,6 +80,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -88,9 +91,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -66,6 +66,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -74,9 +77,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -66,6 +66,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -74,9 +77,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -71,6 +71,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -79,9 +82,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
@@ -2,12 +2,9 @@ package teomakers
import (
"context"
"net/http"
)
type DescribePagesZoneCustomDomainsRequest struct {
sdkRequestBase
ProjectId *string `json:"ProjectId,omitempty"`
}
@@ -28,11 +25,10 @@ func (c *Client) DescribePagesZoneCustomDomains(req *DescribePagesZoneCustomDoma
}
func (c *Client) DescribePagesZoneCustomDomainsWithContext(ctx context.Context, req *DescribePagesZoneCustomDomainsRequest) (*DescribePagesZoneCustomDomainsResponse, error) {
httpreq, err := c.newRequest(http.MethodPost, "/", "DescribePagesZoneCustomDomains", req)
httpreq, err := c.newRequest(req, "DescribePagesZoneCustomDomains")
if err != nil {
return nil, err
} else {
httpreq.SetBody(req)
httpreq.SetContext(ctx)
}
+18 -17
View File
@@ -5,6 +5,7 @@ package teomakers
import (
"encoding/json"
"fmt"
"net/http"
"time"
"github.com/go-resty/resty/v2"
@@ -41,26 +42,29 @@ func (c *Client) SetTimeout(timeout time.Duration) *Client {
return c
}
func (c *Client) newRequest(method string, path string, action string, params sdkRequest) (*resty.Request, error) {
if method == "" {
return nil, fmt.Errorf("sdkerr: unset method")
}
if path == "" {
return nil, fmt.Errorf("sdkerr: unset path")
}
if action == "" {
func (c *Client) newRequest(params any, teoAction string) (*resty.Request, error) {
if teoAction == "" {
return nil, fmt.Errorf("sdkerr: unset action")
}
req := c.rc.R()
req.Method = method
req.URL = path
paramsMap := map[string]any{}
paramsMap["Action"] = teoAction
if params != nil {
params.SetAction(action)
req.SetBody(params)
jsonb, _ := json.Marshal(params)
json.Unmarshal(jsonb, &paramsMap)
if paramsMap["Action"] != teoAction {
return nil, fmt.Errorf("sdkerr: bad request: action mismatch: expected '%s', got '%s'", teoAction, paramsMap["Action"])
}
}
req := c.rc.R()
req.Method = http.MethodPost
req.URL = "/"
req.SetBody(paramsMap)
// WARN:
// DO NOT CALL `req.SetBody` or `req.SetFormData` AGAIN! USE `newRequest` INSTEAD.
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -69,9 +73,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
@@ -1,19 +1,5 @@
package teomakers
type sdkRequest interface {
SetAction(action string)
}
type sdkRequestBase struct {
Action *string `json:"Action,omitempty"`
}
func (r *sdkRequestBase) SetAction(action string) {
r.Action = &action
}
var _ sdkRequest = (*sdkRequestBase)(nil)
type sdkResponse interface {
GetCode() int
GetMessage() string
+3 -3
View File
@@ -73,6 +73,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -81,9 +84,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -62,6 +62,9 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -70,9 +73,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+5
View File
@@ -0,0 +1,5 @@
本模块存在相应的社区 SDK:`github.com/volcengine/ve-tos-golang-sdk`。
但会使得依赖体积显著膨胀,故没有使用。
具体细节见 [PR #1341](https://github.com/certimate-go/certimate/pull/1341)。
+4 -4
View File
@@ -111,6 +111,10 @@ func (c *Client) newRequest(method string, path string, params any) (*resty.Requ
req.SetBody(payloadStr)
req.SetHeader("Content-MD5", payloadMd5Encoded)
req.SetHeader("Content-Type", contentType)
// WARN:
// DO NOT CALL `req.SetBody` or `req.SetFormData` AGAIN! USE `newRequest` INSTEAD.
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -119,10 +123,6 @@ func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetBody` or `req.SetFormData` HERE! USE `newRequest` INSTEAD.
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
+3 -3
View File
@@ -64,6 +64,9 @@ func (c *Client) NewRequest(method string, path string) (*resty.Request, error)
req := c.rc.R()
req.Method = method
req.URL = path
// WARN:
// DO NOT CALL `req.SetResult` or `req.SetError` AGAIN! USE `doRequestWithResult` INSTEAD.
return req, nil
}
@@ -72,9 +75,6 @@ func (c *Client) DoRequest(req *resty.Request) (*resty.Response, error) {
return nil, fmt.Errorf("sdkerr: nil request")
}
// WARN:
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
resp, err := req.Send()
if err != nil {
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)