mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-23 06:32:28 +08:00
使用github的七牛SDK,配置名称Kodo->Qiniu
This commit is contained in:
38
vendor/github.com/qiniu/api.v7/storage/client.go
generated
vendored
Normal file
38
vendor/github.com/qiniu/api.v7/storage/client.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"github.com/qiniu/api.v7/auth/qbox"
|
||||
"github.com/qiniu/x/rpc.v7"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Transport struct {
|
||||
mac qbox.Mac
|
||||
Transport http.RoundTripper
|
||||
}
|
||||
|
||||
func (t *Transport) NestedObject() interface{} {
|
||||
return t.Transport
|
||||
}
|
||||
|
||||
func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
||||
token, err := t.mac.SignRequest(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Authorization", "QBox "+token)
|
||||
return t.Transport.RoundTrip(req)
|
||||
}
|
||||
|
||||
func NewTransport(mac *qbox.Mac, transport http.RoundTripper) *Transport {
|
||||
if transport == nil {
|
||||
transport = http.DefaultTransport
|
||||
}
|
||||
t := &Transport{mac: *mac, Transport: transport}
|
||||
return t
|
||||
}
|
||||
|
||||
func NewClient(mac *qbox.Mac, transport http.RoundTripper) *rpc.Client {
|
||||
t := NewTransport(mac, transport)
|
||||
return &rpc.Client{&http.Client{Transport: t}}
|
||||
}
|
||||
Reference in New Issue
Block a user