mirror of
https://github.com/certimate-go/certimate.git
synced 2026-08-30 18:01:43 +08:00
refactor: clean code
This commit is contained in:
@@ -79,7 +79,7 @@ func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method string, path string, params any, ossResource string) (*resty.Request, error) {
|
||||
func (c *Client) newRequest(method string, path string, params any, xOssResource string) (*resty.Request, error) {
|
||||
if method == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset method")
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func (c *Client) newRequest(method string, path string, params any, ossResource
|
||||
req.QueryParam = requestUrl.Query()
|
||||
req.SetHeader("Content-MD5", payloadMd5Encoded)
|
||||
req.SetHeader("Content-Type", contentType)
|
||||
req.SetHeader("X-API-Resource", ossResource)
|
||||
req.SetHeader("X-API-Resource", xOssResource)
|
||||
req.SetBody(payloadStr)
|
||||
|
||||
// WARN:
|
||||
|
||||
@@ -40,11 +40,7 @@ func NewClient(baseUrl string, service string, optFns ...OptionsFunc) (*Client,
|
||||
return nil, fmt.Errorf("sdkerr: unset secretAccessKey")
|
||||
}
|
||||
|
||||
signer := &signer{
|
||||
accessKeyId: options.AccessKeyId,
|
||||
secretAccessKey: options.SecretAccessKey,
|
||||
service: service,
|
||||
}
|
||||
signer := NewSigner(options.AccessKeyId, options.SecretAccessKey, service)
|
||||
httper := resty.New().
|
||||
SetBaseURL(baseUrl).
|
||||
SetHeader("Accept", "application/json").
|
||||
|
||||
@@ -22,6 +22,14 @@ type signer struct {
|
||||
service string
|
||||
}
|
||||
|
||||
func NewSigner(ak, sk, service string) *signer {
|
||||
return &signer{
|
||||
accessKeyId: ak,
|
||||
secretAccessKey: sk,
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *signer) Sign(req *http.Request) error {
|
||||
// API 签名机制:
|
||||
// https://docs.ksyun.com/documents/40298
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewClient(serverUrl string, optFns ...OptionsFunc) (*Client, error) {
|
||||
}
|
||||
|
||||
httper := resty.New().
|
||||
SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api/v1").
|
||||
SetBaseURL(strings.TrimSuffix(serverUrl, "/")+"/api/v1").
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("User-Agent", app.AppUserAgent).
|
||||
|
||||
@@ -28,10 +28,7 @@ func NewClient(optFns ...OptionsFunc) (*Client, error) {
|
||||
return nil, fmt.Errorf("sdkerr: unset secretKey")
|
||||
}
|
||||
|
||||
signer := &signer{
|
||||
accessKey: options.AccessKey,
|
||||
secretKey: options.SecretKey,
|
||||
}
|
||||
signer := NewSigner(options.AccessKey, options.SecretKey)
|
||||
httper := resty.New().
|
||||
SetBaseURL("https://open.chinanetcenter.com").
|
||||
SetHeader("Accept", "application/json").
|
||||
|
||||
@@ -19,6 +19,13 @@ type signer struct {
|
||||
secretKey string
|
||||
}
|
||||
|
||||
func NewSigner(ak, sk string) *signer {
|
||||
return &signer{
|
||||
accessKey: ak,
|
||||
secretKey: sk,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *signer) Sign(req *http.Request) error {
|
||||
// API 签名机制:
|
||||
// https://www.wangsu.com/document/openapi/api-authentication
|
||||
|
||||
Reference in New Issue
Block a user