mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
30 lines
542 B
Go
30 lines
542 B
Go
package qiniu
|
|
|
|
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)
|
|
}
|