Skip to content

Commit

Permalink
add BucketArchConfig to PutBucket, update copy error return
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoliang committed Aug 25, 2022
1 parent 8659476 commit 3f30427
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
5 changes: 3 additions & 2 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ type BucketPutOptions struct {
CreateBucketConfiguration *CreateBucketConfiguration `header:"-" url:"-" xml:"-"`
}
type CreateBucketConfiguration struct {
XMLName xml.Name `xml:"CreateBucketConfiguration"`
BucketAZConfig string `xml:"BucketAZConfig,omitempty"`
XMLName xml.Name `xml:"CreateBucketConfiguration"`
BucketAZConfig string `xml:"BucketAZConfig,omitempty"`
BucketArchConfig string `xml:"BucketArchConfig,omitempty"`
}

// Put Bucket请求可以在指定账号下创建一个Bucket。
Expand Down
4 changes: 2 additions & 2 deletions cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
// Version current go sdk version
Version = "0.7.37"
Version = "0.7.38"
UserAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
Expand Down Expand Up @@ -316,7 +316,7 @@ func (c *Client) doAPI(ctx context.Context, req *http.Request, result interface{

if result != nil {
if w, ok := result.(io.Writer); ok {
io.Copy(w, resp.Body)
_, err = io.Copy(w, resp.Body)
} else {
err = xml.NewDecoder(resp.Body).Decode(result)
if err == io.EOF {
Expand Down
21 changes: 16 additions & 5 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,32 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O
}
copyOpt.XCosCopySource = u

var bs bytes.Buffer
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name),
method: http.MethodPut,
body: nil,
optHeader: copyOpt,
result: &res,
result: &bs,
}
resp, err := s.client.doRetry(ctx, &sendOpt)
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
if resp != nil && resp.StatusCode == 200 {
if err != nil {
return &res, resp, fmt.Errorf("response 200 OK, but body contains an error, RequestId: %v, Error: %v", resp.Header.Get("X-Cos-Request-Id"), err)

if err == nil { // 请求正常
err = xml.Unmarshal(bs.Bytes(), &res) // body 正常返回
if err == io.EOF {
err = nil
}
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
if resp != nil && resp.StatusCode == 200 {
if err != nil {
resErr := &ErrorResponse{Response: resp.Response}
xml.Unmarshal(bs.Bytes(), resErr)
return &res, resp, resErr
}
}
}

return &res, resp, err
}

Expand Down
22 changes: 17 additions & 5 deletions object_part.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cos

import (
"bytes"
"context"
"encoding/xml"
"errors"
Expand Down Expand Up @@ -271,20 +272,31 @@ func (s *ObjectService) CopyPart(ctx context.Context, name, uploadID string, par
opt.XCosCopySource = sourceURL
u := fmt.Sprintf("/%s?partNumber=%d&uploadId=%s", encodeURIComponent(name), partNumber, uploadID)
var res CopyPartResult
var bs bytes.Buffer
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: u,
method: http.MethodPut,
optHeader: opt,
result: &res,
result: &bs,
}
resp, err := s.client.send(ctx, &sendOpt)
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
if resp != nil && resp.StatusCode == 200 {
if err != nil {
return &res, resp, fmt.Errorf("response 200 OK, but body contains an error, RequestId: %v, Error: %v", resp.Header.Get("X-Cos-Request-Id"), err)

if err == nil { // 请求正常
err = xml.Unmarshal(bs.Bytes(), &res) // body 正常返回
if err == io.EOF {
err = nil
}
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
if resp != nil && resp.StatusCode == 200 {
if err != nil {
resErr := &ErrorResponse{Response: resp.Response}
xml.Unmarshal(bs.Bytes(), resErr)
return &res, resp, resErr
}
}
}

return &res, resp, err
}

Expand Down

0 comments on commit 3f30427

Please sign in to comment.