refactor: reimpl qiniu sdk

This commit is contained in:
Fu Diwei
2025-02-05 21:04:28 +08:00
parent 0e1a964e7c
commit d11fc1c07e
4 changed files with 48 additions and 99 deletions

29
internal/pkg/vendors/qiniu-sdk/auth.go vendored Normal file
View File

@@ -0,0 +1,29 @@
package qiniusdk
import (
"net/http"
"github.com/qiniu/go-sdk/v7/auth"
)
type transport struct {
http.RoundTripper
mac *auth.Credentials
}
func newTransport(mac *auth.Credentials, tr http.RoundTripper) *transport {
if tr == nil {
tr = http.DefaultTransport
}
return &transport{tr, mac}
}
func (t *transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
token, err := t.mac.SignRequestV2(req)
if err != nil {
return
}
req.Header.Set("Authorization", "Qiniu "+token)
return t.RoundTripper.RoundTrip(req)
}