Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bc7b5256c | ||
|
|
95b127211f | ||
|
|
e4b5ad8337 | ||
|
|
1942f2303e | ||
|
|
9a672cde0b | ||
|
|
d18e8cfac2 |
2
cos.go
2
cos.go
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
const (
|
||||
// Version current go sdk version
|
||||
Version = "0.7.11"
|
||||
Version = "0.7.12"
|
||||
userAgent = "cos-go-sdk-v5/" + Version
|
||||
contentTypeXML = "application/xml"
|
||||
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
|
||||
|
||||
@@ -56,7 +56,7 @@ const (
|
||||
kBucket = "cosgosdktest-1259654469"
|
||||
kRegion = "ap-guangzhou"
|
||||
|
||||
// 跨区域复制需要的目标存储桶,地域不能与kBucket存储桶相同。
|
||||
// 跨区域复制需要的目标存储桶,地域不能与kBucket存储桶相同, 目的存储桶需要开启多版本
|
||||
kRepBucket = "cosgosdkreptest"
|
||||
kRepRegion = "ap-chengdu"
|
||||
|
||||
@@ -85,9 +85,9 @@ func (s *CosTestSuite) SetupSuite() {
|
||||
s.Region = p[2]
|
||||
|
||||
// Bucket name
|
||||
pp := strings.Split(p[0], "-")
|
||||
s.Bucket = pp[0]
|
||||
s.Appid = pp[1]
|
||||
pi := strings.LastIndex(p[0], "-")
|
||||
s.Bucket = p[0][:pi]
|
||||
s.Appid = p[0][pi+1:]
|
||||
|
||||
ib := &cos.BaseURL{BucketURL: bucketurl, BatchURL: batchurl}
|
||||
s.Client = cos.NewClient(ib, &http.Client{
|
||||
@@ -185,12 +185,12 @@ func (s *CosTestSuite) TestGetBucket() {
|
||||
}
|
||||
|
||||
func (s *CosTestSuite) TestGetObjectVersions() {
|
||||
opt := &cos.BucketGetObjectVersionsOptions {
|
||||
opt := &cos.BucketGetObjectVersionsOptions{
|
||||
Prefix: "中文",
|
||||
MaxKeys: 3,
|
||||
}
|
||||
_, _, err := s.Client.Bucket.GetObjectVersions(context.Background(), opt)
|
||||
assert.Nil(s.T(), err, "GetObjectVersions Failed")
|
||||
_, _, err := s.Client.Bucket.GetObjectVersions(context.Background(), opt)
|
||||
assert.Nil(s.T(), err, "GetObjectVersions Failed")
|
||||
}
|
||||
|
||||
func (s *CosTestSuite) TestGetBucketLocation() {
|
||||
|
||||
14
helper.go
14
helper.go
@@ -45,7 +45,7 @@ func cloneRequest(r *http.Request) *http.Request {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
|
||||
//
|
||||
// http://www.ecma-international.org/ecma-262/6.0/#sec-uri-syntax-and-semantics
|
||||
func encodeURIComponent(s string) string {
|
||||
func encodeURIComponent(s string, excluded ...[]byte) string {
|
||||
var b bytes.Buffer
|
||||
written := 0
|
||||
|
||||
@@ -71,6 +71,18 @@ func encodeURIComponent(s string) string {
|
||||
|
||||
continue
|
||||
}
|
||||
if len(excluded) > 0 {
|
||||
conti := false
|
||||
for _, ch := range excluded[0] {
|
||||
if ch == c {
|
||||
conti = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if conti {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b.WriteString(s[written:i])
|
||||
|
||||
24
object.go
24
object.go
@@ -115,12 +115,12 @@ func (s *ObjectService) GetPresignedURL(ctx context.Context, httpMethod, name, a
|
||||
authTime = NewAuthTime(expired)
|
||||
}
|
||||
authorization := newAuthorization(ak, sk, req, authTime)
|
||||
sign := encodeURIComponent(authorization)
|
||||
sign := encodeURIComponent(authorization, []byte{'&','='})
|
||||
|
||||
if req.URL.RawQuery == "" {
|
||||
req.URL.RawQuery = fmt.Sprintf("sign=%s", sign)
|
||||
req.URL.RawQuery = fmt.Sprintf("%s", sign)
|
||||
} else {
|
||||
req.URL.RawQuery = fmt.Sprintf("%s&sign=%s", req.URL.RawQuery, sign)
|
||||
req.URL.RawQuery = fmt.Sprintf("%s&%s", req.URL.RawQuery, sign)
|
||||
}
|
||||
return req.URL, nil
|
||||
|
||||
@@ -256,20 +256,26 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O
|
||||
}
|
||||
|
||||
var res ObjectCopyResult
|
||||
if opt == nil {
|
||||
opt = new(ObjectCopyOptions)
|
||||
copyOpt := &ObjectCopyOptions{
|
||||
&ObjectCopyHeaderOptions{},
|
||||
&ACLHeaderOptions{},
|
||||
}
|
||||
if opt.ObjectCopyHeaderOptions == nil {
|
||||
opt.ObjectCopyHeaderOptions = new(ObjectCopyHeaderOptions)
|
||||
if opt != nil {
|
||||
if opt.ObjectCopyHeaderOptions != nil {
|
||||
*copyOpt.ObjectCopyHeaderOptions = *opt.ObjectCopyHeaderOptions
|
||||
}
|
||||
if opt.ACLHeaderOptions != nil {
|
||||
*copyOpt.ACLHeaderOptions = *opt.ACLHeaderOptions
|
||||
}
|
||||
}
|
||||
opt.XCosCopySource = u
|
||||
copyOpt.XCosCopySource = u
|
||||
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.BucketURL,
|
||||
uri: "/" + encodeURIComponent(name),
|
||||
method: http.MethodPut,
|
||||
body: nil,
|
||||
optHeader: opt,
|
||||
optHeader: copyOpt,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
|
||||
Reference in New Issue
Block a user