mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-09 05:59:50 +00:00
refactor: clean code
This commit is contained in:
parent
a51f85826c
commit
3fcea4ba2f
31
internal/pkg/vendors/qiniu-sdk/client.go
vendored
31
internal/pkg/vendors/qiniu-sdk/client.go
vendored
@ -6,10 +6,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/qiniu/go-sdk/v7/auth"
|
"github.com/qiniu/go-sdk/v7/auth"
|
||||||
|
|
||||||
xhttp "github.com/usual2970/certimate/internal/utils/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const qiniuHost = "https://api.qiniu.com"
|
const qiniuHost = "https://api.qiniu.com"
|
||||||
@ -136,25 +135,29 @@ func (c *Client) UploadSslCert(name, commonName, certificate, privateKey string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) sendReq(method string, path string, body io.Reader) ([]byte, error) {
|
func (c *Client) sendReq(method string, path string, body io.Reader) ([]byte, error) {
|
||||||
req := xhttp.BuildReq(fmt.Sprintf("%s/%s", qiniuHost, path), method, body, map[string]string{
|
path = strings.TrimPrefix(path, "/")
|
||||||
"Content-Type": "application/json",
|
|
||||||
})
|
req, err := http.NewRequest(method, fmt.Sprintf("%s/%s", qiniuHost, path), body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
|
||||||
if err := c.mac.AddToken(auth.TokenQBox, req); err != nil {
|
if err := c.mac.AddToken(auth.TokenQBox, req); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
respBody, err := xhttp.ToRequest(req)
|
client := http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
r, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer respBody.Close()
|
return r, nil
|
||||||
|
|
||||||
res, err := io.ReadAll(respBody)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user